sam268
July 16, 2014, 8:00pm
1
This is my newest script.
#pragma strict
var LOL;
function OnMouseDown () {
LOL = GameObject.FindGameObjectWithTag("selectedlane");
transform.LOL.tag = "lane";
transform.gameObject.tag = "selectedlane";
print(gameObject.tag);
}
function Update () {
if (gameObject.tag == "selectedlane"){
gameObject.renderer.material.color = Color.yellow;
}
if (gameObject.tag == "lane"){
gameObject.renderer.material.color = Color.red;
}
}
and I get this error Assets/Standard Assets (Mobile)/Scripts/SelectLane.js(7,11): BCE0019: ‘LOL’ is not a member of ‘UnityEngine.Transform’.
yeah it is named LOL… dont ask my brain is fried.
instead of …transform.LOL.tag =… use …LOL.tag =
LOL is not a member of transform, that is correct!
LOL is the gameobject you are looking for. And therefore you must change that tag on LOL directly.
You are using LOL after the transform.
It needs to be in front.
While you are at it, you should always include a default error catcher. If LOL did not exist, then not to cause an error.
also… You should define what your type is. So the engine doesn’t guess later.
var LOL : GameObject;
function OnMouseDown () {
LOL = GameObject.FindGameObjectWithTag("selectedlane");
if(LOL) LOL.transform.tag = "lane";
transform.gameObject.tag = "selectedlane";
print(gameObject.tag);
}
As WidmeNoel says, also, if you have to use a transform you have to write its name first.
If you wanted to change LOL’s position, you would have used LOL.transform.position not transform.LOL.position
sam268
July 16, 2014, 8:31pm
5
awwww bigmisterb you did it!
it works now thanks alot! I was figuring (and hoping) it was just some language issue and not a bad code.