Flip car in air | Check object is grounded unity easy tutorial
ASSALAM o alaikum Code:
//////////////// car flip script code /////////////////////////////////////
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class Flip : MonoBehaviour,IPointerDownHandler,IPointerUpHandler
{
public Transform carChild;
bool buttonPressed;
public Vector3 rotationFactor;
Vector3 factorHere;
public float flipSpeed = .05f;
public void OnPointerDown(PointerEventData eventData)
{
buttonPressed = true;
}
public void OnPointerUp(PointerEventData eventData)
{
buttonPressed = false;
}
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (buttonPressed)
{
factorHere = Vector3.Lerp(factorHere,rotationFactor,flipSpeed);
}
else
{
factorHere = Vector3.Lerp(factorHere,new Vector3(0,0,0),flipSpeed);
}
carChild.Rotate(factorHere);
}
}
////////////////// check object grounded script code //////////////////
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CheckGrounded : MonoBehaviour
{
public GameObject[] flipButtons;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
private void OnTriggerStay(Collider other)
{
if (other.gameObject.CompareTag("Ground"))
{
foreach (var flipButton in flipButtons)
{
flipButton.SetActive(false);
}
}
}
private void OnTriggerExit(Collider other)
{
if (other.gameObject.CompareTag("Ground"))
{
foreach (var flipButton in flipButtons)
{
flipButton.SetActive(true);
}
}
}
}
////////////////////////////////////////////////////////////////////////////////////////
daff and trumpet credits https://youtu.be/vKZizPY1bnc
/////////////////////////////////////////////////////////////////////////////////////////////
ASSALAM o alaikum
All codes and concepts and videos from this channel are non copyrighted and free to use because we believe that knowledge should be freely available for everyone
But kindly give those people credit whom I have given in description if you use their work
/////////////////////////////////////////////////////////////////////////////////////////////
Unity is a cross-platform game engine developed by Unity Technologies, first announced and released in June 2005 at Apple Worldwide Developers Conference as a Mac OS X game engine. The engine has since been gradually extended to support a variety of desktop, mobile, console and virtual reality platforms. Wikipedia
Initial release date: June 8, 2005
Stable release: 2022.1.13 (Tech Stream); 2021.3.8f1 (LTS) /; August 11, 2022; 2 months ago; August 9, 2022; 2 months ago
Preview release: 2022.2.0b4 (Beta); 2023.1.0a4 (Alpha) /; August 8, 2022; 3 months ago; July 28, 2022; 3 months ago
Developer: Unity Technologies
Original author: Unity Technologies
License: Proprietary software
Programming languages: C#, C++