Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
using UnityEngine;
using UnityEngine.EventSystems;
public class Interaction : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
{
private Rigidbody Body;
private bool IsRotate = false;
// Start is called before the first frame update
void Start()
{
this.Body = gameObject.AddComponent<Rigidbody>();
this.Body.useGravity = false;
this.Body.angularDrag = 0f;
}
// Update is called once per frame
void Update()
{
}
public void OnPointerEnter(PointerEventData eventData)
{
if (!this.IsRotate)
{
this.Body.angularVelocity = new Vector3(0, 2f, 0);
this.IsRotate = true;
}
}
public void OnPointerExit(PointerEventData eventData)
{
if (this.IsRotate)
{
this.Body.angularVelocity = Vector3.zero;
this.IsRotate = false;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment