- Home /
Can you change static variables from another script?
I cant seem to find answer on internet. I have this attached to a camera:
var projectile : Rigidbody; var speed =868;
static var bullets = 0;
static var score = 0;
function Update() {
if( Input.GetButtonDown( "Fire1" ) ) {
if (bullets < 10)
{
var instantiatedProjectile : Rigidbody = Instantiate(
projectile, transform.position, transform.rotation );
instantiatedProjectile.velocity = transform.TransformDirection( Vector3( 0, 0, speed ) );
Physics.IgnoreCollision( instantiatedProjectile. collider,
transform.root.collider );
bullets +=1;
}
else
{
bullets = 0;
score = 0;
Application.LoadLevel(0);
}
} }
And in a seperate code attached to different object I have this:
function OnControllerColliderHit(hit : ControllerColliderHit)
{
if(hit.gameObject.tag == "Bullets")
{
DragPhysics.score += 1;
}
}
However when Bullets collides with the target the score remains zero.
Answer by PrimeDerektive · Feb 24, 2011 at 02:48 PM
OnControllerColliderHit() only registers when the object is hit by a CharacterController currently in the midst of a .Move or .SimpleMove (I'm assuming your bullets are not using CharacterControllers), you probably want to use OnCollisionEnter(collision : Collision).
Answer by burnumd · Feb 24, 2011 at 02:47 PM
Yes, you can change static variables from other scripts as long as the static variables are public (which they are by default in Javascript). Have you ensured that your collision is actually being triggered (by placing Debug statements in OnControllerColliderHit)? Also, be sure that your target has a CharacterController and you adhere to the collision matrix laid out here.
Your answer
Follow this Question
Related Questions
Distance in a Trajectory of a projectile 0 Answers
moving an object with swipe for ios? 3 Answers
projectile issue please help me its annoying mme badly 1 Answer
Projectile Script Problems. 1 Answer
Launching a Projectile to a Raycast 1 Answer