public void EquipWeapon(string weapon, int weapPos) { Destroy(weapons[weapPos]); Vector3 p = new Vector3(hands[weapPos % 2].position.x, hands[weapPos % 2].position.y - 0.4f, hands[weapPos % 2].position.z); weapons [weapPos] = Instantiate(Resources.Load(weapon) as GameObject, p, transform.rotation) as GameObject; switch (weapon) { case "APS403": { weaponScripts[weapPos] = new APS403(); weapons[weapPos].transform.Rotate(0f, 0f, 8f * ((weapPos % 2) == 0 ? -1 : 1)); break; } case "SHL009": { weaponScripts[weapPos] = new SHL009(); float rot = -165; weapons[weapPos].transform.rotation = Quaternion.Euler(new Vector3(90, rot, 0)); break; } case "SHS309": { weaponScripts[weapPos] = new SHS309(); weapons[weapPos].transform.Rotate(0, 0, (weapPos % 2 == 0 ? -1 : 0) * 180); weapons[weapPos].transform.position = new Vector3(p.x, p.y + 0.8f, p.z + 0.5f); break; } } weapons [weapPos].transform.SetParent(hands [weapPos % 2]); if (weapPos >= 2) { weapons[weapPos].SetActive(false); } }
void buildWeapons(string[] weaponNames) { Transform shoulderL = transform.FindChild("CurrentMech/metarig/hips/spine/chest/shoulder.L"); Transform shoulderR = transform.FindChild("CurrentMech/metarig/hips/spine/chest/shoulder.R"); Transform[] hands = new Transform[2]; hands [0] = shoulderL.FindChild ("upper_arm.L/forearm.L/hand.L"); hands [1] = shoulderR.FindChild ("upper_arm.R/forearm.R/hand.R"); GameObject[] weapons = new GameObject[4]; Weapon[] weaponScripts = new Weapon[4]; for (int i = 0; i < weaponNames.Length; i++) { Vector3 p = new Vector3(hands[i%2].position.x, hands[i%2].position.y-0.4f, hands[i%2].position.z); weapons [i] = Instantiate(Resources.Load(weaponNames [i]) as GameObject, p, transform.rotation) as GameObject; switch (weaponNames[i]) { case "APS403": { weaponScripts[i] = new APS403(); break; } case "SHL009": { weaponScripts[i] = new SHL009(); float rot = -135; weapons[i].transform.rotation = Quaternion.Euler(new Vector3(90,rot,0)); weapons[i].transform.position.Set(p.x, p.y, p.z); break; } } weapons [i].transform.SetParent (hands [i % 2]); } weapons [2].SetActive (false); weapons [3].SetActive (false); }
private void buildWeapons(string[] weaponNames) { if (weapons != null) { for (int i = 0; i < weapons.Length; i++) { if (weapons[i] != null) { Destroy(weapons[i]); } } } weapons = new GameObject[4]; weaponScripts = new Weapon[4]; for (int i = 0; i < weaponNames.Length; i++) { Vector3 p = new Vector3(hands[i % 2].position.x, hands[i % 2].position.y - 0.4f, hands[i % 2].position.z); weapons [i] = Instantiate(Resources.Load(weaponNames [i]) as GameObject, p, transform.rotation) as GameObject; switch (weaponNames[i]) { case "APS403": { weaponScripts[i] = new APS403(); weapons[i].transform.Rotate(0f, 0f, 8f * ((i % 2) == 0 ? -1 : 1)); break; } case "SHL009": { weaponScripts[i] = new SHL009(); float rot = -135; weapons[i].transform.rotation = Quaternion.Euler(new Vector3(90, ((i % 2) == 0?rot - 60:rot), 0)); weapons[i].transform.position.Set(p.x, p.y, p.z); break; } case "SHS309": { weaponScripts[i] = new SHS309(); weapons[i].transform.Rotate(0, 0, (i % 2 == 0 ? -1 : 0) * 180); weapons[i].transform.position = new Vector3(p.x + ((i % 2) == 0 ? 0 : 1) * 0.25f, p.y + 0.8f, p.z + 0.5f); break; } } weapons [i].transform.SetParent(hands [i % 2]); } weaponOffset = 0; weapons [2].SetActive(false); weapons [3].SetActive(false); }
void buildWeapons(string[] weaponNames) { Transform shoulderL = transform.Find("CurrentMech/metarig/hips/spine/chest/shoulder.L"); Transform shoulderR = transform.Find("CurrentMech/metarig/hips/spine/chest/shoulder.R"); Transform[] hands = new Transform[2]; hands [0] = shoulderL.Find("upper_arm.L/forearm.L/hand.L"); hands [1] = shoulderR.Find("upper_arm.R/forearm.R/hand.R"); if (weapons != null) { for (int i = 0; i < 4; i++) { if (weapons[i] != null) { Destroy(weapons[i]); } } } weapons = new GameObject[4]; Weapon[] weaponScripts = new Weapon[4]; for (int i = 0; i < weaponNames.Length; i++) { Vector3 p = new Vector3(hands[i % 2].position.x, hands[i % 2].position.y - 0.4f, hands[i % 2].position.z); weapons [i] = Instantiate(Resources.Load(weaponNames [i]) as GameObject, p, transform.rotation) as GameObject; switch (weaponNames[i]) { case "APS403": { weaponScripts[i] = new APS403(); break; } case "SHL009": { weaponScripts[i] = new SHL009(); float rot = -135; weapons[i].transform.rotation = Quaternion.Euler(new Vector3(90, rot, 0)); weapons[i].transform.position.Set(p.x, p.y, p.z); break; } } weapons [i].transform.SetParent(hands [i % 2]); } weapons [2].SetActive(false); weapons [3].SetActive(false); }
private void buildWeapons (string[] weaponNames) { weapons = new GameObject[4]; weaponScripts = new Weapon[4]; for (int i = 0; i < weaponNames.Length; i++) { Vector3 p = new Vector3(hands[i%2].position.x, hands[i%2].position.y - 0.4f, hands[i%2].position.z); weapons [i] = Instantiate(Resources.Load(weaponNames [i]) as GameObject, p, transform.rotation) as GameObject; switch (weaponNames[i]) { case "APS403": { weaponScripts[i] = new APS403(); break; } case "SHL009": { weaponScripts[i] = new SHL009(); float rot = -165; weapons[i].transform.rotation = Quaternion.Euler(new Vector3(90,rot,0)); break; } } weapons [i].transform.SetParent (hands [i % 2]); } weaponOffset = 0; weapons [2].SetActive (false); weapons [3].SetActive (false); }