EXAMPLE: If Cursor Is Touching Lever AND ALSO Pressing Action Button(E) Than Play Animation.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LeverON : MonoBehaviour {
public GameObject Cursor;
public GameObject Lever;
void OntriggerEnter (Collider other) {
if (other.CompareTag ("Cursor")) {
Debug.Log("Cursor Has Collided")
if(Input.GetButtonDown("Action")) {
Debug.Log("Play Animation");
Lever.GetComponent<Animation> ().Play ("LeverOn");
}
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LeverON : MonoBehaviour {
public GameObject Cursor;
public GameObject Lever;
// As long as a gameobject stays within the trigger, this will be called over and over
void OnTriggerStay(Collider other) {
if(Input.GetButtonDown("Action")) {
if (other.CompareTag ("Cursor")) {
Debug.Log("Play Animation");
Lever.GetComponent<Animation> ().Play ("LeverOn");
}
}
}
}