1
如果玩家不移动并且只是站在预制子弹中就是正常运动(图A)。 我的预制件在玩家跑步或移动时表现出不良行为(图片B)。怪异行为实例子弹预制
这是我firePos脚本:
public class FirePos : MonoBehaviour {
public bool _facingRight;
public GameObject bulletRight, bulletLeft;
bool canShootFire;
// Use this for initialization
void Start() {
canShootFire = true;
_facingRight = GameObject.Find ("Player").GetComponent<PlayerManager>();
}
// Update is called once per frame
void Update() {
if(Input.GetKeyDown(KeyCode.K) && canShootFire && GameObject.Find("Player").GetComponent<PlayerManager>().facingRight){
canShootFire = false;
Instantiate (bulletRight, transform.position, transform.rotation);
StartCoroutine ("Firing");
}
if(Input.GetKeyDown(KeyCode.K) && canShootFire && !GameObject.Find("Player").GetComponent<PlayerManager>().facingRight){
canShootFire = false;
Instantiate (bulletLeft, transform.position, transform.rotation);
StartCoroutine ("Firing");
}
}
IEnumerator Firing(){
yield return new WaitForSeconds (.5f);
canShootFire = true;
}
}
这对子弹运动
public class bulletRight : MonoBehaviour {
public float speed;
// Use this for initialization
void Start() {
}
// Update is called once per frame
void Update() {
transform.Translate (Vector2.right*speed*Time.deltaTime,0);
Destroy (gameObject,1.5f);
}
}
你应该发送bullet脚本。子弹如何移动? –
是否将此脚本附加到您的Player对象? – Hristo
@MustafaErdemKöşkoke我只是这样做。 –