I made a video to show what excacly happens. You can see me dragging the 2 weapons into the hierarchy, they appear in the scene. Then when I click on the play button, I show you where the 2 weapons are located at the beginning of the game and I show you what happens if I scroll down. When I scroll down the Axe scales way down but stays at the same position.
[Click here for Video here][1]
[1]: https://www.youtube.com/watch?v=3Ux9Ur67KDw&feature=youtu.be
**Here follows the code:**
#pragma strict
public var weapons : GameObject[];
private var currentw : int;
private var nmrweapons : int;
private var weaponslot : Transform;
function Start () {
weaponslot = transform.Find("male_model@Idle/male_model/malemodel|forearm.R.001/malemodel|hand.R/Empty_weapon");
weapons = GameObject.FindGameObjectsWithTag("Weapon");
currentw = 0;
nmrweapons = weapons.Length;
Debug.Log("test");
}
function Update () {
if(Input.GetAxis("Mouse ScrollWheel")<0) {
if(currentw == nmrweapons){
currentw = 0;
}
else{
currentw = 1;
}
Debug.Log("test1");
Changeweapon(currentw);
}
}
function Changeweapon(cw:int){
Debug.Log("test3");
weapons[cw].transform.parent = weaponslot;
weapons[cw].transform.localPosition = Vector3.zero;
weapons[cw].transform.localRotation = Quaternion.identity;
weapons[cw].transform.localScale = Vector3.one;
}
I really do not understand anymore what to do, I've tried loads of things. But I just do not have enough knowledge of coding, so I really do need someone to explain me, why its doing what its doing. I am still new at coding so it's probably a dumb mistake.
Thanks in advance
↧