This question was
closed Dec 20, 2016 at 11:48 AM by
VikingTheMad for the following reason:
The question is answered, right answer was accepted
Question by
VikingTheMad · Dec 19, 2016 at 11:04 AM ·
cutscene
Make a player look at an object and move
I'm trying to make it so whenever my player walks into certain areas they stop, look at an object, then back out. The code I've got so far applied to my player, trying to interact with a cube with no mesh renderer and a box collider w/ trigger. Though for some reason I'm not getting stopped by it when I walk to it, just going through.
using UnityEngine;
using System.Collections;
public class Caught : MonoBehaviour {
public Transform target;
public GameObject watchedArea;
public GameObject Player;
public string AreaTag;
public float MovementX;
public float MovementY;
public float MovementZ;
//Make the player look at an object and move
void OnTriggerEnter(Collider other) {
if (other.gameObject.CompareTag (AreaTag)) {
Player.transform.LookAt(target);
Player.transform.position = new Vector3(MovementX, MovementY, MovementZ);
}
}
}
Comment