- Home /
HELP! i want to write to look at the target and give a force to follow
How to write it right??
heatrocketaimingenemyplane.js
static var targett : GameObject; var myTimer : float = 0.0; function OnTriggerStay (other : Collider) {
if(other.gameObject.tag == "enemyplane")
{
aim.renderer.material.mainTexture = aimred;
if(myTimer < 3){
myTimer += Time.deltaTime;
}
if(myTimer >= 3){
lol = true;
}
if(lol && myTimer >= 3){
aim.renderer.material.mainTexture = aimgreen;
***targett = other.gameObject;***
print(targett);
}
}
}
function OnTriggerExit (){ lol = false; myTimer = 0.0; aim.renderer.material.mainTexture = aimnormaltexture; }
missile.js
function Update(){
transform.LookAt(heatrocketaimingenemyplane.targett);
}
Assets/Scripts/Weapons/NewBehaviourScript 2.js(4,17): BCE0023: No appropriate version of 'UnityEngine.Transform.LookAt' for the argument list '(UnityEngine.GameObject)' was found.
Answer by Aleks 1 · Apr 12, 2011 at 09:29 PM
try changing this:
if(lol && myTimer >= 3){
aim.renderer.material.mainTexture = aimgreen;
***targett = other.gameObject;***
print(targett);
}
to this:
if(lol == true && myTimer >= 3){
aim.renderer.material.mainTexture = aimgreen;
***targett = other.gameObject;***
print(targett);
}
or: if(lol >= 3 && myTimer >= 3){
} whichever applies.
Answer by mggameboy123 · Apr 13, 2011 at 01:55 PM
but my problem is that it cannot convert to trasform the collider, and i dont know how to fix
Answer by mggameboy123 · Apr 13, 2011 at 02:01 PM
OH YEAHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH I MADE IT!!!!!!!!!!!!!!!!!!!!!!!!!
targett = other.gameObject.transform;
I'm happy :)
Your answer
Follow this Question
Related Questions
How to hit two objects with only one shot (raycast) 0 Answers
Calling a function from colliding with an Object 4 Answers
Internal collisions 1 Answer
OverlapSphere not detecting target 1 Answer
Player Attacking Enemy Issue 0 Answers