Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

how to call score method from different class ???

Discussion in 'Scripting' started by karammaks, May 26, 2014.

  1. karammaks

    karammaks

    Joined:
    Apr 6, 2014
    Posts:
    146
    Hi
    i have asked this question before but didn't get the wanted code , i have a game with multible spawners and with game score , the game will start with 1 spawner , for example if the score becomes 100 , the second spawner will work or start spawning , the problem in my code is that the Score is exist in a object trigger to calculate the objects score which hit that trigger , i think i have 2 solution for this but i want some one to help me with coding it
    1- in the same object trigger i have to put if statement , if score >= 100 , activate Spawner2 ( Spawner2 should be already inactive).
    2- in each spawner , i have to call the Score method from the object trigger class , for example :

    Code (csharp):
    1. void SpawnObject() {
    2.  
    3.         if (Score==10){
    4. .
    5. .
    6. .
    7. .
    8. }
    9. }
    but i dont know how to call the score method from that object trigger :( , so please if any one know how to code any of those solution , please help me with this

    Thanks
     
  2. karammaks

    karammaks

    Joined:
    Apr 6, 2014
    Posts:
    146
    please any one can help ??
     
  3. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,680
    I think what you need to apply is a system of managers and delegates. Meaning, you have one manager for any sub members. And in turn these sub members, may have sub members themself.


    As long as I have access to the objects before run, I use the scriptName as a variable. Any object now, with this script can fill this slot. In turn, this script, can now access the object with scriptName.



    Code (csharp):
    1.  
    2. public scriptName scriptData;
    3.  
    4.  
    5. void doSomething(){
    6. scriptData.DoThis();
    7. scriptData.someVariable = thisValue;
    8.  
     
  4. karammaks

    karammaks

    Joined:
    Apr 6, 2014
    Posts:
    146
    Thx renman , actually im looking of someone can code one of the solutions i've suggested , i think its easy to do like so , but im new in unity
     
  5. A.Killingbeck

    A.Killingbeck

    Joined:
    Feb 21, 2014
    Posts:
    483
    Yep, it's pretty easy. Only takes a couple of years to get good at programming, good luck!