- Home /
How to make a GameObject separate from a prefab?
Alright so here's what I'm trying to do: I instantiate an enemy kamikaze from a random point, In the function start the kamikaze is told to look at a target, The target for the kamikaze is randomly moving along the y axis, the target is a prefab, but it's just an empty game object.
Here's my problem, the script's work and the kamikaze looks at the target in the start, but the kamikaze looks at the prefab of the target's, while ignoring the real one which is constantly moving. For example the prefab of the target it set at (1000, 500, 1000), and this is the point the the kamikaze looks at, rather than the moving target in the scene. How do I say "look at the real target, not the prefab". I made the target a prefab because if I didn't I couldn't drag and drop it into kamikaze prefab as the target. If there's no way to do this is there a way to set it as the target? Or is there a way to do something like:
transform.LookAt("the value of the target's x,y, and z")Thanks for any help I've been stuck on this forever.
Here's the script's: This is the script I use to make the kamikaze move and look at the target:
var target : Transform; var speed : int; var looking : boolean = false;
function Update () {
//$$anonymous$$ake's the kamikaze move forward transform.Translate(0,0,speed * Time.deltaTime);
//Call's the look function if(looking == false) { Look(); }
}
//$$anonymous$$ake's the kamikaze look at the target function Look () {
looking = true;
transform.LookAt(target);
}
And here's the script that make's the target move:
var rangeY1 : float; var rangeY2 : float; var moveTime : float; var move : boolean = true;
function Update () {
//Call's the move function if(move == true) {
$$anonymous$$ove();
}
}
//$$anonymous$$ove's the kamikaze's target function $$anonymous$$ove () { move = false;
yield WaitForSeconds(moveTime);
transform.position.y = Random.Range(rangeY1, rangeY2);
move = true; }
Never$$anonymous$$d I solved it I just have to put the real object in a different layer than the prefab.
Hey Posly, how exactly did you fix it? I'm doing the exact same thing :( haha
Your answer
Follow this Question
Related Questions
How to get a prefab to look at a target? 1 Answer
Accessing children of instances vs children of original prefab 1 Answer
Instantiate prefab from original position to click mouse point position 0 Answers
Sphere and text mesh in prefab share transformation matrix 0 Answers
Bullet Prefab spawning in multiple random positions and rarely the correct one (Unity 3D) 1 Answer