Skip to content

Instantly share code, notes, and snippets.

@KeithNdhlovu
Created March 1, 2019 10:55
Show Gist options
  • Save KeithNdhlovu/78a175e31a377cdd3b2c95515bb4f0e4 to your computer and use it in GitHub Desktop.
Save KeithNdhlovu/78a175e31a377cdd3b2c95515bb4f0e4 to your computer and use it in GitHub Desktop.
Unity Transition between animations, in this case we have a case where we need to open the door when the right mouse is clicked pointing to the door
using UnityEngine;
using System.Collections;
public class HouseDoor : MonoBehaviour {
public Animation doorOpenAnimation;
public Animation doorCloseAnimation;
public bool doorOpen= false;
void Update() {
if (Input.GetMouseButtonDown(0)) {
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit)) {
if (doorOpen == false) {
OpenDoor();
}
else if (doorOpen == true) {
CloseDoor();
}
}
}
}
public void OpenDoor(){
doorOpenAnimation.Play();
doorOpen = true;
}
public void CloseDoor() {
doorCloseAnimation.Play();
doorOpen = false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment