Hey. I’m working on a LookAt camera script that changes when you click on a specific type of object. (In this case a game bal.) I’m having trouble figuring out Tags. When I set one in the editor, it becomes an Invalid Tag. I think I’m missing something.
using UnityEngine;
using System.Collections;
public class ChangableLookAt : MonoBehaviour
{
public Transform lookAt;
public float smooth = 5F;
Quaternion lastRotation;
Quaternion goalRotation;
void FixedUpdate ()
{
if (lookAt != null)
{
Debug.DrawLine(lookAt.position, transform.position, Color.gray);
Vector3 difference = lookAt.position - transform.position;
Quaternion rotation = Quaternion.LookRotation(difference, Vector3.up);
goalRotation = rotation;
}
}
void Update ()
{
if (Input.GetMouseButtonDown(0))
{
Ray ray = camera.ScreenPointToRay (Input.mousePosition);
RayCollision coll = Dynamics.CastRay (transform.position, ray.direction);
if (coll != null)
{
GOComponent goc = (GOComponent) coll.collider;
if (goc.CompareTag("Selectable"))
{
lookAt = goc.transform;
}
}
}
}
void Awake ()
{
lastRotation = transform.rotation;
goalRotation = lastRotation;
}
void LateUpdate ()
{
lastRotation = Quaternion.Slerp (lastRotation, goalRotation, smooth * Time.deltaTime);
transform.rotation = lastRotation;
}
}
-Jon