- Home /
Question by
gregorio80 · Apr 29, 2014 at 02:51 PM ·
instancesid
Variables related to instance
Hello, i have some Trees on my scene (cloned).
and this is the script attached to every (cloned) tree in the scene
#pragma strict
//MANAGE_TREE IS THE NAME OF THIS SCRIPT
var numeroclick: int;
var abbattuto: boolean;
var touched : boolean;
function Start () {
numeroclick=0;
}
function OnMouseDown()
{
if (touched == true) //touched works well!
{
numeroclick=numeroclick+1;
Debug.Log("click nr°:"+numeroclick+" on "+gameObject.name+" (tree down?: "+abbattuto+")");
}
if (numeroclick==20 )
{
abbattuto=true;
numeroclick=0;
Debug.Log("tree is down!");
//routine of falling tree
}
if (numeroclick==20 && abbattuto == true)
{
//if abbattuto=true the tree is on the floor
//on 20° click i will generate some wood
numeroclick=0;
Debug.Log("tree is chopped!");
//generate some istances of wooden chunks
}
}
function Update () {
touched = GameObject.Find("player/Main Camera").GetComponent(raycaster).TouchSomething ;
}
Now i have an Object (an hatchet) and i would like to load AnimationA if the TREE is falled on the floor or AnimationB if the tree is still not chopped.
Here is the script attached to hatchet:
//albero33 is the name of the gameobject for the trees
function Update ()
{
touched = GameObject.Find("player/Main Camera").GetComponent(raycaster).TouchSomething ;
what = GameObject.Find("player/Main Camera").GetComponent(raycaster).TouchWhat ;
abb = GameObject.Find("albero33").GetComponent(manage_tree).abbattuto ;
//Touched:boolean:does the raycast touch something?
//What: what the collider.name touched by raycast?
//abb: variable abbattuto in Manage_tree script
if (presa==true) //this works well :)
{
po(); //attaching the hatchet to the player
if ( Input.GetButtonDown("Fire1") )
{
print("abbattuto?"+abb);
if (what=="albero33" && abb == false) {
this.animation.Play("anim_ascia");
}
if (what=="albero33" && abb == true) {
this.animation.Play("ascia_updown");
}
}
}
}
Abb is always FALSE. And i know why: this is because i get the variable from the firstGamobject named "albero33" and not from the one that i'm CLICKING!!
how can i get out of thiss mess? I really dont get it...
I need to get the variables of THE INSTANCE of the tree that i'm clicking :)
avery help is appreciated.. :(
Comment
Your answer
