我是一个团结的初学者,所以现在我正在从事像蠕虫游戏这样的回合制游戏。但由于某种原因,我的攻击脚本仅适用于左侧单元,而不适用于右侧单元。具体来说,当我为右侧的子弹射击时,我实例化的子弹走错了方向,但它们对左侧的子弹完全按照预期工作。我对字符按钮有单独的脚本,但我对项目符号使用相同的脚本。
项目符号脚本
public float speed;
public float posX, posY;
// Use this for initialization
void Start () {
rigidbody2D.AddForce (new Vector2 (posX, posY), ForceMode2D.Impulse);
}
// Update is called once per frame
void Update () {
//transform.Translate (speed * Time.deltaTime, 0, 0);
}
void OnCollisionEnter2D(Collision2D c){
if (c.gameObject.tag == "Base") {
Destroy(gameObject);
Destroy(c.gameObject);
}
else if(c.gameObject.tag == "Player2"){
Destroy(gameObject);
Destroy(c.gameObject);
}
}
void OnBecameInvisible () {
Destroy(gameObject);
}
字符脚本
gameObject go 是子弹的预制件
public GameObject go;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if(gameObject.tag == "Player2"){
if(Input.GetKeyUp(KeyCode.Backspace)){
Instantiate(go,transform.position,transform.rotation);
}
}
}
}