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 rOBY GAMES · May 09, 2015 at 01:00 PM · playerobjectshot

GameObject not deactivated.

Hi.

2d game. the character in this script to count the strokes from 10 to 0. In this script I posted a (var myObject: GameObject;) that it will be deactivated as soon as the count reaches 0 shots, but this is not working. The count when 0 marks the object is not deactivated.

Any solution?

thanks

 #pragma strict
  
 var Prefab : Rigidbody2D;
 var colpo1 : float = 60;
 var dirX = Vector3.right;
 var myObject : GameObject; 
 
 function Update () 
 {
  if(Input.GetButtonDown("Fire1")) 
 {
    myObject.SetActive(true);
    
    if(Collisions.GRENADE_AMMO > 0) && myObject.SetActive false;
    
  
 if(!Prefab || !colpo1)
 
      {
 
     }
   else
    {
 var PrefabCreate: Rigidbody2D = Instantiate(Prefab,GameObject.Find("Projectile Spawn").transform.position, Quaternion.identity);
   
   PrefabCreate.rigidbody2D.velocity = colpo1 * dirX;    
      
      Collisions.GRENADE_AMMO --;
      GameObject.Find("g_Count").guiText.text = ""+Collisions.GRENADE_AMMO;
      print("YOU NOW HAVE " + Collisions.GRENADE_AMMO + "GRENADES");
      
         
      }
    }
 }
Comment
Add comment · Show 2
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
avatar image fighder · May 09, 2015 at 02:47 PM 0
Share

why is there a && before you deactivate the gameObject?

avatar image njkvnk · May 09, 2015 at 03:01 PM 0
Share

You also may need to change Collisions.GRENADE_A$$anonymous$$$$anonymous$$O > 0 to Collisions.GRENADE_A$$anonymous$$$$anonymous$$O =< 0 after you fix it, unless I am interpreting your problem incorrectly.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by njkvnk · May 09, 2015 at 03:11 PM

Instead of .setActive false; try .setActive(false);

Comment
Add comment · Share
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
avatar image
0

Answer by LawgiverSS2 · May 09, 2015 at 03:12 PM

You probably want to write instead:

  if(Collisions.GRENADE_AMMO <= 0) 
  {
      myObject.SetActive(false);
  }
Comment
Add comment · Show 4 · Share
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
avatar image rOBY GAMES · May 09, 2015 at 03:34 PM 0
Share

Thanks LawgiverSS2. Now the count continues after zero with -1, -2, -3, when I still click. the gameobject now works correctly. now how to solve the problem of counting?

I am now using this script after editing.

pragma strict

 var Prefab : Rigidbody2D;
 var colpo1 : float = 60;
 var dirX = Vector3.right;
 var myObject : GameObject; 
 
 function Update () 
 {
  if(Input.GetButtonDown("Fire1")) 
 {
   {
 myObject.SetActive(true);
  } 
    
    if(Collisions.GRENADE_A$$anonymous$$$$anonymous$$O <= 0) 
    
      {
       myObject.SetActive(false);
   }
    
    
 
 if(!Prefab || !colpo1)
   
      
      {
 
     }
   else
    {
 var PrefabCreate: Rigidbody2D = Instantiate(Prefab,GameObject.Find("Projectile Spawn").transform.position, Quaternion.identity);
   
   PrefabCreate.rigidbody2D.velocity = colpo1 * dirX;    
      
      Collisions.GRENADE_A$$anonymous$$$$anonymous$$O --;
      GameObject.Find("g_Count").guiText.text = ""+Collisions.GRENADE_A$$anonymous$$$$anonymous$$O;
      print("YOU NOW HAVE " + Collisions.GRENADE_A$$anonymous$$$$anonymous$$O + "GRENADES");
      
         
      }
    }
 }



avatar image fighder · May 09, 2015 at 03:40 PM 0
Share

if you just wanna stop the count, you can either have the condition

 if(Collisions.GRENADE_A$$anonymous$$$$anonymous$$O > 0){
 Collisions.GRENADE --;
 }

or alternatively, just have this at the end of the function:

 if(Collisions.GRENADE_A$$anonymous$$$$anonymous$$O < 0){
 Collisions.GRENADE_A$$anonymous$$$$anonymous$$O = 0;
 }
avatar image rOBY GAMES · May 09, 2015 at 03:48 PM 0
Share

Ciao fighder. I tried but continues to count -1, -2, -3, etc.

script associate:

 #pragma strict
 
 static var GRENADE_A$$anonymous$$$$anonymous$$O = 0;
 static var temp : int = 5;
 var myObject : GameObject;
 
 
 
 function OnTriggerEnter2D (col : Collider2D)  
 { 
   if(col.gameObject.tag== "Player")
   {
        
        
        Destroy(gameObject);
       
                                     
        GRENADE_A$$anonymous$$$$anonymous$$O += 10;
        
        myObject.SetActive(true);
        
        print("YOU NOW HAVE "+ GRENADE_A$$anonymous$$$$anonymous$$O +"GRENADES");
        GameObject.Find("g_Count").guiText.text = ""+GRENADE_A$$anonymous$$$$anonymous$$O;
       
            Destroy(gameObject);    
    }    
   }
 
avatar image LawgiverSS2 · May 09, 2015 at 04:49 PM 0
Share

Please show your current conditions testing GRENADE_A$$anonymous$$$$anonymous$$O

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

22 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 avatar image avatar image

Related Questions

Shot is activated only when I walk. 2 Answers

Activate a Object 1 Answer

Check for an instantiated object farthest from player? 1 Answer

Having a particle effect stick to player 0 Answers

Can i add texture to multiple layers of player? and how? 0 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