Created
March 1, 2019 10:55
-
-
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
This file contains hidden or 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 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