using System.Collections; using System.Collections.Generic; using UnityEngine; public class FireController : MonoBehaviour { public GameObject BulletPrefab; GameObject player; // Start is called before the first frame update void Start() { player = GameObject.Find("cat"); } // Update is called once per frame void Update() { // move int direction = 0; if(Input.GetKeyDown(KeyCode.LeftShift)) { // 透過 localScale取得主角目前方向 if (player.transform.localScale.x >=0.0) { direction = 1; } else { direction = -1; } Debug.Log("Player direction is"); Debug.Log(direction); Debug.Log("Player localScale x is "); Debug.Log(player.transform.localScale.x); Vector2 p1 = this.player.transform.position; Vector2 p2 = new Vector2(p1.x+1, p1.y); if (direction == 1) { p2 = new Vector2(p1.x+1, p1.y); BulletPrefab.transform.localScale = new Vector3(1, 1, 1); } if (direction == -1) { p2 = new Vector2(p1.x-1, p1.y); BulletPrefab.transform.localScale = new Vector3(-1, 1, 1); } // 主角位置.x + 1來產生子彈 Instantiate(BulletPrefab, p2, transform.rotation); // 以主角的位置來產生子彈 // Instantiate(BulletPrefab,this.player.transform.position, transform.rotation); } } }