Quantcast
Channel: Questions in topic: "clone"
Viewing all articles
Browse latest Browse all 508

How clone prefab and change it with not change original

$
0
0
I'm trying to create game with random weapons stats with holding 2 weapons in same time 1 in inventory 1 in use(in developt i use 3 for testing). I use rocket and lazer prefab with same scrypt who hold its stat and when i change from rocket to lazer all work normaly. But if i have 2 rockets betwens i want change i need create a clone of rocket prefab with differents stats. But if i try change scrypt stats of clone i change also a original. scrypt what i use in weapons public class WeaponStats : MonoBehaviour { public int WeaponDamage = 40; public float WeaponReloadTime = 1; } And the main scrypt where i have problems public class PControler : MonoBehaviour { public GameObject[] WeaponType; GameObject obgToSpawn; public float fireRateRoket; private float nextFire; void Update () { if (Input.GetKeyDown (KeyCode.Alpha1)) { DataHolder.WeaponType = 0;} if (Input.GetKeyDown (KeyCode.Alpha2)) { DataHolder.WeaponType = 1; if (Input.GetKeyDown (KeyCode.Alpha3)) { WeaponType[2] = WeaponType[1]; DataHolder.WeaponType = 2; WeaponType[2].GetComponent().WeaponDamage = 100; WeaponType[2].GetComponent().WeaponReloadTime = 2; WeaponType[2].transform.localScale=new Vector3 (3f, 3f, 3f) ; WeaponType[2] = Instantiate(WeaponType[2], transform.position, Quaternion.identity) as GameObject; } //and later use mouse to fire if (Input.GetButton ("Fire1") == true&& Time.time > nextFire){ nextFire = Time.time + WeaponType[DataHolder.WeaponType].GetComponent().WeaponReloadTime; Instantiate (WeaponType[DataHolder.WeaponType], plPosition, plyerPosition.rotation);}} There how connected this prefabs and scrypths ![alt text][1] So if i want get back to original weapon[1] its stats changed to same as weapon[2] . Also changing only original prefab what sit in game folder. ![alt text][2] I'm can use changing stats when press 2 to make its normal like i do is on press 3, but its help if only one object use that weapon. If there more than 1 object with rockets its will be changing all object on scene with rockets. And i know that i change original with that code but need help with find how create copy of that prefab and latter change it with no changing original. [1]: /storage/temp/101263-all-inspector.png [2]: /storage/temp/101264-using-changing.png

Viewing all articles
Browse latest Browse all 508

Trending Articles