Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
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
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

20 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Cloud recognition in Vuforia 0 Answers

how to give id to tag in xml 1 Answer

Is there an impossible value for Object.GetInstanceID() 0 Answers

Can different variables referencing the same object return different instance IDs? 0 Answers

Network Programming in Unity 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges