I made a simple machine gun, when i enter the trigger its setting camera to true and and when i exit the trigger the camera goes back to false, all of that work for now,
i want to add:
when i enter i want to make my current weapon to off (so i wont see him)
but its not working
and when i exit the trigger set it back to true
Some codes:
var Cam : GameObject;
function OnTriggerEnter(c : Collider){
if(c.gameObject.tag == "Player"){
Cam.SetActiveRecursively(true);
Pickup.curWeapon.SetActiveRecursively(false);
}
}
function OnTriggerExit(c : Collider){
if(c.gameObject.tag == "Player"){
Cam.SetActiveRecursively(false);
Pickup.curWeapon.SetActiveRecursively(true);
}
}
This line is from the script i switch weapons
Pickup.curWeapon.SetActiveRecursively(true);
I ain’t going to write any lines of code as I simply can not say First-person or even gun games are my strong point, I script games that do not use guns, very sorry, I will say one thing though.
When I can not seem to make triggers make say a object go invisible and not be accessed I use render and collider switchers.
References for this is:
gameObject.Find("YourGameObjectName").renderer.enabled = false;
gameObject.Find("YourGameObjectName").collider.enabled = false;
Then I would use two scripts toggle a script off and on, therefore this stops the weapon or in your case gun from actually working when it should not be.
References for this code is:
<Yourgameobject>.GetComponent(yourscriptname).enabled = false;
Make a separate script to actually turn the weapon back to its normal functionality, you do this by copying the script into a new script and changing all false’s to true.
Does this work for you?
Thank you, if i only knew i cant call the function Find to an game object which is not active, anyway i got the code working.
Now i got one more question;
i want it to shoot just again some bug that need to be fixed:
if(Input.GetButton("Fire1")){
var bulletT : Rigidbody = Instantiate(bullet, spawn.position, spawn.rotation);
bulletT.AddForce(transform.forward * 1000);
}
spawn variable (that in the code) is a transform and its the spawn bullet position.
bullet variable is a GameObject.
The problem is its shooting the bullet to the right instead of forward.