- Home /
Is not a Member of Collisions
Hi, I'm new to programming and I'm using Javascript, I'm having a problem with the script though.
GRENADE_AMMO' is not a member of 'Collisions'.
"Collisions = Collisions.GRENADE_AMMO --;"
"Collisions.GRENADE_AMMO += 8;"
These are linked to the error i think.
Can anyone help me please?
enter code here
var Collisions;
function OnControllerColliderHit(hit : ControllerColliderHit) { if(hit.gameObject.tag == "CrateGrenades")
{ //destroy the ammobox Destroy(hit.gameObject);
Collisions = GRENADE_AMMO --;
//add ammo to inventory Collisions.GRENADE_AMMO += 8; }
}
}
This is not enough information to help you. Why do you think the two lines of code you poster are valid? What do you think they 'do'?
Answer by DaveA · Jun 02, 2011 at 10:51 PM
How have you defined Collisions? Because there is no GRENADE_AMMO member variable in it. And you are setting Collisions to Collisions.GRENADE_AMMO which is strange. Can you post more code?
Answer by Dryden Richardson · Jun 02, 2011 at 10:55 PM
"Well, there are two peices of code, not very effietient of me but here's a piece. I'm following a tutorial btw.
//create the perfab var Crate = Instantiate(grenadePrefab, transform.position, Quaternion.identity);
//add force to the prefab grenadePrefab.rigidbody.AddForce(transform.forward * 2000);
Collisions = Collisions.GRENADE_AMMO --; print ("You Now Have "+ GRENADE_AMMO +" Grenades"); }
New Code function OnControllerColliderHit(hit : ControllerColliderHit) { if(hit.gameObject.tag == "CrateGrenades")
{ //destroy the ammobox Destroy(hit.gameObject);
Collisions = GRENADE_AMMO --;
//add ammo to inventory Collisions.GRENADE_AMMO += 8;
function OnControllerColliderHit(hit : ControllerColliderHit) { if(hit.gameObject.tag == "CrateGrenades")
{ //destroy the ammobox Destroy(hit.gameObject);
Collisions = GRENADE_AMMO --;
//add ammo to inventory Collisions.GRENADE_AMMO += 8;"
First, you should get familiar with the 101/010 button above the edit area. That will format your code so it looks readable. Second, you should not answer your question, you should comment, or edit your original question. Third, there is no pre-defined Collisions class, so where is that defined (show code)? It would look like 'class Collisions' or 'var Collisions'
Okay, I'll use Unity Answers better now when asking questions thanks.