I have hit the forums and Youtube which is how I have gotten as far as I have getting the ray cast to work as well as getting an animation to play on my gameobject. The problem is that I want the animation to trigger on rayCastHit rather than ( as in the code below) when the player enters the trigger. Since I started all this in C# trying to find how to do this hit roadblocks as most of what I find is in JS. So below, instead of the OnTriggerEnter (Collider other) {
if(other.tag == “Player”)
trigger the animation, how do I make the raycast do it?
this is my camera raycast script, that works and tells me what gameobject it is looking at:
public class CameraRaycast : MonoBehaviour {
Camera camera;
void Start() {
camera = GetComponent<Camera>();
}
void Update() {
Ray ray = camera.ViewportPointToRay(new Vector3(0.5F, 0.5F, 0));
RaycastHit hit;
if (Physics.Raycast(ray, out hit))
print("I'm looking at " + hit.transform.name);
else
print("I'm looking at nothing!");
}
}
and this is the script that triggers the animation when the player enters the trigger. Please help. I have been at this for days and feel I am near the endzone here.
using UnityEngine;
using System.Collections;
public class dancerenabled : MonoBehaviour {
private GameObject dancertest;
Animation Dance;
// Use this for initialization
void Start () {
Dance = GameObject.Find("dancertest").GetComponent<Animation>();
//animation = GetComponent <Animation> ();
}
// Update is called once per frame
void OnTriggerEnter (Collider other) {
if(other.tag == "Player")
{
Dance.enabled = true;
}
}
}