Hi, i am trying to male an FPS game, so i have a character and two weapons, but what should i do to change weapon ?? i need to change one object with another… What does it work ?
Someone can explain me this or give me some examples ??
Thank you so much
Hi,
What you are trying to achieve is really darn simple all you nedd to have is some programming knowledge
**Create a new empty gameobject and make your weapos as the child of the new object and attach the script to the object created **
//Note this script is in JavaScript but since i use lot of C# i amy have made few syntax problems without my knowledge
public var Weapon:GameObject;
function Update()
{
if(Input.GetKeyDown("1")) // Use keycode.Alpha1 instead used this tome it simpler to understand
{
SetActive(1);
}
if(Input.GetKeyDown("2")) // If you press 2 then select second object
{
SetActive(2);
}
}
function SetActive(WeaponInt:int)
{
for(i:int =0; i < transform.childCount;i++) // iterate through this Object's Children
{
if(i == WeaponInt) // if Selected int == current int that is i then Enable the object
transform.GetChild(i).gameObject.SetActive(true);
else // Disable it
transform.GetChild(i).gameObject.SetActive(false);
}
}
you can just hide one and show other by code
or you can play hiding animation and then play showing other animation