Hey everyone, im new to Unity and I’ve been slowly learning how to use it and java through tutorials, but I’ve hit a snag. I have a script that’s suppose to make me throw a grenade. It is suppose to make my gun disappear, when i click the left mouse button throw the grenade, (Iv’e made the animation) then throw a prefab sphere that i created, but all it does is layer on top of my gun and do nothing. I’ve checked with the Scripter i followed and he said the script is fine, but maybe one of you can help me? Ill add the two scripts im using for it below, maybe its not in the scripts that its not working? Anyway please help!!
My Choose Equipment Script -
//First Gun, AR,SMG,Ect
var Primary : GameObject;
//Second Gun, Pistol Ect
var Secondary : GameObject;
var GrenadeObj : GameObject;
// Use this for initialization
function Start ()
{
Secondary.SetActiveRecursively(false);
Primary.SetActiveRecursively(true);
GrenadeObj.SetActiveRecursively(false);
}
// Update is called once per frame
function Update ()
{
if(Input.GetKeyDown(“1”) && Secondary.active == true){
Primary.SetActiveRecursively(true);
Secondary.SetActiveRecursively(false);
}
if(Input.GetKeyDown("2") && Primary.active == true){
Primary.SetActiveRecursively(false);
Secondary.SetActiveRecursively(true);
}
if(Input.GetButtonDown("Grenade"))
{
GrenadeObj.SetActiveRecursively(true);
}
}
My Throw Grenade Script -
var Grenade : Rigidbody;
var Throw : String;
var Spawn : Transform;
private var _MainCam : GameObject;
// Use this for initialization
function Start ()
{
_MainCam = GameObject.FindGameObjectWithTag(“WeapCam”);
}
// Update is called once per frame
function Update ()
{
if(Input.GetButtonDown(“Grenade”))
{
gameObject.animation.Play(Throw);
gameObject.animation[Throw].speed =1.5;
_MainCam.GetComponent(ChooseEquipment).Primary.SetActiveRecursively(false);
_MainCam.GetComponent(ChooseEquipment).Secondary.SetActiveRecursively(false);
Toss();
}
}
function Toss(){
yield WaitForSeconds(1);
gren = Instantiate(Grenade,Spawn.position,Spawn.rotation);
Grenade.rigidbody.AddForce(transform.forward * 1000);
gameObject.SetActiveRecursively(false);
_MainCam.GetComponent(ChooseEquipment).Primary.SetActiveRecursively(true);
}
Please Help!