我的拍摄脚本有些困难。通常情况下,子弹工作正常但有时(完全随机)我不能再射击了。 我可以看到我的角色旁边的精灵,但它不会移动。如果发生这种情况,我将无法修复,直到我重新开始游戏。
武器脚本在播放器上
public class weaponScript : MonoBehaviour {
public Transform shotPrefab;
public float shootingRate = 0.25f;
private float shootCooldown;
public float xtrans;
void Start(){
shootCooldown = 0f;
}
void Update(){
if (shootCooldown > 0){
shootCooldown -= Time.deltaTime;
}
}
public void Attack(bool isEnemy)
{
if (CanAttack){
if(PinkPlayerControler.playerFaceRight == true)
xtrans = transform.position.x + 2f;
else if(PinkPlayerControler.playerFaceRight == false)
xtrans = transform.position.x - 2f;
shootCooldown = shootingRate;
var shotTransform = Instantiate(shotPrefab) as Transform;
//shotTransform.position = transform.position;
shotTransform.position = new Vector3(xtrans, transform.position.y,transform.position.z);
}
}
public bool CanAttack
{
get{
return shootCooldown <= 0f;
}
}
}
另外两个在子弹上
public class bulletMove : MonoBehaviour {
public Vector2 jumpVector;
public int speed;
void Update(){
startMovement ();
}
void startMovement(){
if (PinkPlayerControler.playerFaceRight == true) {
rigidbody2D.velocity = transform.right.normalized * speed;
Destroy(this);
}
else {
rigidbody2D.velocity = -transform.right.normalized * speed;
Destroy(this);
}
}
void OnTriggerEnter2D(Collider2D other){
if (other.tag == "bulletDeath" || other.tag == "groundTrap")
Destroy (this.gameObject);
else if (other.tag == "destroyByBullet") {
Debug.Log("blockHit");
Destroy (other.gameObject);
Destroy(this.gameObject);
}
}
}
拍摄剧本
public class shootScript : MonoBehaviour {
public static int damage = 1;
public static bool hit = false;
void Start()
{
Destroy(gameObject, 2);
}
void Update(){
if (hit == true)
Destroy (this.gameObject);
}
void OnTriggerEnter2D(Collider2D other)
{
if (other.tag == "bullet") {
Destroy(other.gameObject);
}
}
}
我不明白为什么它会停止工作这么随意。
提前致谢:)
Chrizzly