Skip to content

Instantly share code, notes, and snippets.

@hatsunea
Last active November 20, 2022 06:20
Show Gist options
  • Save hatsunea/877ae274acaa34c31d58669f3fd05d8a to your computer and use it in GitHub Desktop.
Save hatsunea/877ae274acaa34c31d58669f3fd05d8a to your computer and use it in GitHub Desktop.
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