iv been working on a weapons manager and i have it spawning and switching weapons… but im having a hard time with rotation and parenting the weapons, what i want is to make the weapon a child of “WeaponPoint” and as for the rotation i want it to use the forward faceing of “WeaponPoint” if anyone could help i would be heartful. heres my code
var WeaponsInInventory : GameObject[];
var EquippedWeapon : int;
var WeaponPoint : Transform;
function Update () {
// ***********CODE TO SCROLL THROUGH WEAPONS *****************************
if (Input.GetAxis("Mouse ScrollWheel") > 0){
EquippedWeapon++;
EquipWeapon();
Debug.Log(EquipedWeapon);
}
if (Input.GetAxis("Mouse ScrollWheel") < 0){
EquippedWeapon--;
EquipWeapon();
Debug.Log(EquipedWeapon);
}
if (EquippedWeapon < 0){
EquipedWeapon = WeaponsInInventory.length; // if we try to go into negetive numbers loop to the the last weapon in our inventory.
EquipWeapon();
}
if (EquippedWeapon > WeaponsInInventory.length - 1){
EquipedWeapon = 0; // if we try to go into a number greater than the number of weapons in our inventory loop to the first.
EquipWeapon();
}
}
function EquipWeapon() {
Destroy (WeaponsInInventory[EquipedWeapon]); // destroy the weapon we are holding before spawning our new weapon
Instantiate(WeaponsInInventory[EquipedWeapon], GameObject.Find("WeaponPoint").transform.position, Quaternion.identity); // spawn our waeapon
Debug.Log(WeaponsInInventory[EquipedWeapon] + "was spawned");
WeaponsInInventory[EquipedWeapon]transform.parent = GameObject.Find("WeaponPoint").transform.position; // make our weapon a child of our weapon spwan point
}
P.S im still new to programing and my script is probably way off so try to go easy on me