|
This is the script can nayone fix the error
static var runaround: boolean = true; var speed:float = 20; var rotatespeed:float = 10; var dis:float = 1; var LeftRight:float = 2; var infront:float = 1; var home : String; private var direction:float = 60; function Start() { var home =gameObject.FindWithTag(home); } function Update(){ if(comehome){ //transform.LookAt(home); transform.LookAt(home.transform, Vector3.up); transform.Translate(Vector3.forward*speed*Time.deltaTime); } if(runaround){
} } this is the error BCE0019: 'transform' is not a member of 'String'.
(comments are locked)
|
|
As I mentioned in my last comment. You could save some performance if "home" is the same game object at all times. Like this:
You see the difference? Now "home" is a string, which is the tag name. Whereas the variable home is of the type GameObject. As you probably know. String is just a bunch of letters or chars ('a', 'b', 'c'), whereas GameObject is a class. With an instance of GameObject (also known as an object), you can refer to the transform of the game object. Transform is required of the: when i try that it says The best overload for the method 'UnityEngine.GameObject.FindWithTag(String)' is not compatible with the argument list '(UnityEngine.GameObject)'.
Dec 28 '10 at 08:01 PM
zeuo
(comments are locked)
|
|
Try: or it can be transform.LookAt(home.transform.position); and for specifically axis transform.LookAt(home.transform.position.y);
Dec 28 '10 at 06:56 PM
Uriel_96
it workes for like the first 4 seconds then i get NullReferenceException
Dec 28 '10 at 06:57 PM
zeuo
Can you post the error that the debug log is giving? The LookAt(home.transform) should work fine forever.
Dec 28 '10 at 07:23 PM
Bob5602
Well, if it suddenly can't find any object with the tag home. Then it will give null refs. So if you check for this, then you should never get a null ref. But here is a question for you. If "home" is always the same game object, then cache it, instead of calling find on every update (this is expensive).
Dec 28 '10 at 07:27 PM
Ejlersen
the problem is that i cant even get it to work, anything i try im always getting errors. i just simply want the lookat to look at home and home is a tag thats all
Dec 28 '10 at 07:52 PM
zeuo
(comments are locked)
|

Please make sure all of your code is formatted with the code markup (select all the lines while editing your question, then click the 01 icon), to make it easier to read. Thanks!