Search Unity

Change GameObject to var

Discussion in 'Scripting' started by The3DKnight, Mar 21, 2013.

  1. The3DKnight

    The3DKnight

    Joined:
    Feb 8, 2011
    Posts:
    240
    Hi guys.
    I've been trying to make weapon pickup script.And the problem is how to switch GameObject variables.
    Here's the part of script:

    Code (csharp):
    1.  
    2.  
    3. //Weapons in game
    4.  
    5. var First: GameObject;
    6. var Second : GameObject;
    7. var WeaponIndex : int = 0;
    8.  
    9.  
    10. function Update ()
    11. {
    12. if(Input.GetAxis("Mouse ScrollWheel")){
    13.  
    14. curWeapon +=1;
    15. }
    16.  
    17. if(curWeapon == 1)
    18.  
    19. {
    20.  
    21. Second.gameObject.SetActiveRecursively(true);
    22. First.gameObject.SetActiveRecursively(false);
    23. }
    24.  
    25.  
    26.  
    27. //Chage part
    28. //*****
    29. //*****
    30. //*****
    31. if (WeaponIndex == 1)
    32. {
    33. //First weapon change to weapon that's in var Num1
    34.         First == Num1;
    35.        
    36. }
    37. }
    38.  
    It doesn't show any errors but i just won't work.
    How can i get GameObject that's on Num1 be on First variable?

    Any ideas? Ty :)
    -3DK
     
  2. BPPHarv

    BPPHarv

    Joined:
    Jun 9, 2012
    Posts:
    318
    At a glance I think you want
    Code (csharp):
    1. First = Num1;
    instead of
    Code (csharp):
    1.  First == Num1;
    for line 32
     
  3. The3DKnight

    The3DKnight

    Joined:
    Feb 8, 2011
    Posts:
    240
    Thank you a lot. :D