i am trying to make a shop script for my first person shoot game. i switch weapons buy deleting the old weapon and instantiating a new one from a prefab. the weapon is suppose to auto position it's self according to variables in it's script, those variables are used in the aim script attached to the camera witch is a parent of the gun.
the system works fine except that i get this error when i switch weapons
transform.localPosition assign attempt for 'vzr8(Clone)' is not valid. Input localPosition is { -45.218674, -0.350000, NaN }.
UnityEngine.Transform:set_localPosition(Vector3)
aim:Update() (at Assets/scripts/player/gun/aim.js:33)
can any one tell me what it means and how to fix it. btw here is my shop script
private var toggle : boolean = false;
private var player : Transform;
private var skin: GUIStyle;
private var bg: Texture;
var guns : Transform[];
function Start(){
player = gameObject.FindWithTag("Player").transform;
skin = gameObject.FindWithTag("Master").GetComponent("master_gameInterface").skin;
bg = gameObject.FindWithTag("Master").GetComponent("master_gameInterface").bg;
}
function OnGUI() {
var dist = Vector3.Distance(player.position, transform.position);
myStyle = new GUIStyle();
myStyle.normal.textColor = Color.cyan;
myStyle.font = skin.font;
if(dist<5){
if(Input.GetKey(KeyCode.E)){
master_gameInterface.pause = true;
toggle = true;
}
if(toggle==false)
GUI.Label(Rect(Screen.width/2,Screen.height/2,200,200), "Press E to enter Shop", myStyle);
}
if(master_gameInterface.toggle)
toggle = false;
if(toggle){
GUILayout.BeginArea(Rect(Screen.width/2-100,Screen.height/2-200,200,400), bg);
GUILayout.BeginVertical();
for(var i=0;i<guns.Length;i++){
if(GUILayout.Button(guns[i].GetComponent("gun").name, skin)){
if(player.GetChild(2).GetChild(0))
Destroy(player.GetChild(2).GetChild(0).gameObject);
var me = Instantiate(guns[i], player.position, Quaternion.identity);
me.parent = player.GetChild(2);
me.localPosition = player.GetChild(2).position;
player.GetChild(2).GetComponent("aim").gun = me;
}
}
GUILayout.Label("\n");
if(GUILayout.Button("Done", skin)){
master_gameInterface.pause = false;
toggle = false;
}
GUILayout.EndVertical();
GUILayout.EndArea();
}
}
function deleteGun(){
for (var child : Transform in transform) {
child.position += Vector3.up * 10.0;
}
}
[Edit by Berenger : code formatting]
asked
Feb 27 '12 at 03:31 PM
dick
16
●
7
●
7
●
11