Quantcast
Channel: Questions in topic: "clone"
Viewing all articles
Browse latest Browse all 508

Enemy prefab not keeping transform

$
0
0
var target : Transform; //the enemy's target var moveSpeed = 3; //move speed var rotationSpeed = 3; //speed of turning var respawn : Transform; var dead : boolean = false; var myTransform : Transform; //current transform data of this enemy function Awake() { myTransform = transform; //cache transform data for easy access/preformance } function Start() { } function Update () { //rotate to look at the player myTransform.rotation = Quaternion.Slerp(myTransform.rotation, Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed*Time.deltaTime); //move towards the player myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime; } function OnTriggerEnter(theCollision : Collider) { if(theCollision.gameObject.name=="Spotlight") { Destroy(gameObject); Debug.Log("Dead"); dead = true; } Respawn(); } function Respawn() { if(dead == true) { Instantiate(respawn, Vector3(0,0,0), Quaternion.identity); dead = false; } } This is my enemy code, the Update() function allows the enemy to follow the player around, this works well when its just a single enemy in the project view as it uses the target Transform to tell the enemy which object to go towards. I have set it up a prefab so that the enemy will respawn when they collide with the players flashlight. The only thing is, they are all clones of the enemy and the target which is set to player when i copied it into the prefab now becomes set to None and the newly spawned enemies will just stand by idly. Can anyone explain to me as to why this is?

Viewing all articles
Browse latest Browse all 508

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>