- Home /
Question by
mawak93 · Nov 02, 2013 at 02:29 PM ·
instantiatespawnsnake
I want to respawn the food everytime the snake collides with it
using UnityEngine; using System.Collections;
public class Food : MonoBehaviour { Transform Mytransform; Transform LOL;
public GameObject FoodPre;
// Use this for initialization
void Start () {
LOL = transform;
LOL.position= new Vector3(Random.Range (-8,8),Random.Range (-3.4f,5.4f),0);
}
// Update is called once per frame
void Update () {
}
void OnTriggerEnter(Collider collider)
{ if (collider.gameObject.CompareTag ("Snake")){
Destroy (this.gameObject);
Respawn ();
}
}
public void Respawn()
{
Instantiate (FoodPre,LOL.position,Quaternion.identity);
}
}
This is my current code......after i eat the first food it respawns but after i eat the clone it doesnt respawn.....any ideas?
Comment
Is this script applied to the clone? Are you destroying the object this is attached too?
Please write an answer and accept it or close the question.
Your answer
Follow this Question
Related Questions
Spawn: Instantiate GameObject 1 Answer
Issue With Spawning Enemies (javascript) 2 Answers
How Do I Add An Instantiated Object To An Array? 3 Answers
How do i prevent an object instantiating another object straight away 2 Answers
snake game tail problems 0 Answers