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*.GetComponent("gun").name, skin)){*
-
if(player.GetChild(2).GetChild(0))*
-
Destroy(player.GetChild(2).GetChild(0).gameObject);*
_ var me = Instantiate(guns*, player.position, Quaternion.identity);_
_ me.parent = player.GetChild(2);_
_ me.localPosition = player.GetChild(2).position;_
_ player.GetChild(2).GetComponent(“aim”).gun = me;_
_ }_
_ }*_
* GUILayout.Label("
");*
* 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]