void Start() { // We start with the simple shot myBullet = WeaponScript.typeBullet.Simple; WeaponScript weapon = this.transform.Find("WeaponSpiral").GetComponent <WeaponScript>(); weapon.shotPrefab.rotation = Quaternion.identity; }
void Update() { // 3 - Retrieve axis information float inputX = Input.GetAxis("Horizontal"); float inputY = Input.GetAxis("Vertical"); // 4 - Movement per direction movement = new Vector2( maxSpeed * System.Math.Sign(inputX), maxSpeed * System.Math.Sign(inputY)); // 5 - Checking weapon changement if (Input.GetKeyDown(KeyCode.Tab)) { // We simply switch to the next type of weapon int typeInt = (int)(myBullet); myBullet = (WeaponScript.typeBullet)((typeInt + 1) % 3); swap = true; } // 6 - Shooting bool shoot = false; if (Input.GetKey(KeyCode.Space)) { shoot = true; } if (shoot) { WeaponScript[] weapons = GetComponentsInChildren <WeaponScript>(); foreach (WeaponScript weapon in weapons) { if (weapon != null && canAttack()) { if (myBullet == weapon.myType) { // false because the player is not an enemy if (swap && myBullet == WeaponScript.typeBullet.Spiral) { Debug.Log("hi"); this.transform.Find("WeaponSpiral").rotation = Quaternion.identity; weapon.shotPrefab.rotation = Quaternion.identity; swap = false; } weapon.Attack(false, myBullet); } } } } Vector3 pos = Camera.main.WorldToViewportPoint(transform.position); pos.x = Mathf.Clamp01(pos.x); pos.y = Mathf.Clamp01(pos.y); transform.position = Camera.main.ViewportToWorldPoint(pos); }