ChangableLookAt

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

You need create the tag in the tag manager first.
(Edit → Project Settings → Tags)

After you have created the tag you can assign it to a game object.

This thread is nearly 20 years old!!!

Please don’t necro-post. If you have a new question, make a new post. It’s FREE!!

How to report your problem productively in the Unity3D forums:

http://plbm.com/?p=220

This is the bare minimum of information to report:

  • what you want
  • what you tried
  • what you expected to happen
  • what actually happened, log output, variable values, and especially any errors you see
  • links to actual Unity3D documentation you used to cross-check your work (CRITICAL!!!)

The purpose of YOU providing links is to make our job easier, while simultaneously showing us that you actually put effort into the process. If you haven’t put effort into finding the documentation, why should we bother putting effort into replying?

If you post a code snippet, ALWAYS USE CODE TAGS:

How to use code tags: Using code tags properly

  • Do not TALK about code without posting it.
  • Do NOT post unformatted code.
  • Do NOT retype code. Use copy/paste properly using code tags.
  • Do NOT post screenshots of code.
  • Do NOT post photographs of code.
  • Do NOT attach entire scripts to your post.
  • ONLY post the relevant code, and then refer to it in your discussion.