- Home /
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");
}
}
}
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.
Answer by LawgiverSS2 · May 09, 2015 at 03:12 PM
You probably want to write instead:
if(Collisions.GRENADE_AMMO <= 0)
{
myObject.SetActive(false);
}
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");
}
}
}
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;
}
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);
}
}
Please show your current conditions testing GRENADE_A$$anonymous$$$$anonymous$$O
Your answer
Follow this Question
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