Last active
November 20, 2022 06:20
-
-
Save hatsunea/877ae274acaa34c31d58669f3fd05d8a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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