- Home /
Parent mesh problem
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.
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
Answer by giulio-pierucci · Feb 15, 2015 at 11:40 PM
The row:
weaponslot = transform.Find("male_model@Idle/male_model/malemodel|forearm.R.001/malemodel|hand.R/Empty_weapon");
fails, because the name is wrong ( ...@Idle/malemodel/...) then weaponslot is null
this row:
weapons[cw].transform.parent = weaponslot;
is weapons[cw].transform.parent = null;
I understand that weapons[cw].transform.parent = null < I understand that part but what is wrong about:
weaponslot = transform.Find("male_model@Idle/male_model/malemodel|forearm.R.001/malemodel|hand.R/Empty_weapon");
That are the excact names as they are in the hierarchy literally copied. You mean it has to be: weaponslot = transform.Find("male_model@Idle/male_model/malemodel|forearm.R.001/malemodel|hand.R/null"); ?
Problem is solved already there was some other mistakes other then the one you told me that I didn't see -.- thanks for that!
Your answer
Follow this Question
Related Questions
How to instantiate a GameObject in a scene and keep world transform? 3 Answers
Child object getting transformed out side the scene on collision? 1 Answer
Trying to make an object "Flee" from the player but it won't work? 3 Answers
Rotation drift with transform.eulerAngles 0 Answers
Parenting Transforms, Must (still) Set Parent at 0,0,0 ? 1 Answer