当我拿礼物这样的东西时,我试图给我的飞船子弹加电,我已经尝试了很多,但是没事:(任何人都可以帮我吗 我试过了,但是这段代码对我来说是行不通的,我在很多网站上进行搜索,结果发现我的船被撞坏了,当它撞到敌人时,我的船就被销毁了:)>
我的船舶代码是:
public GameObject shot;
public int coolDown = 0;
public int typeshoot = 1;
public Vector3 shotPosotion;
private GameObject forO;
public int computer = 0;
void Start()
{
forO = GameObject.FindGameObjectWithTag("forO");
}
// Update is called once per frame
void FixedUpdate()
{
if (Input.GetButton("Fire1"))
{
if (computer <= 0)
{
shotPosotion.x = this.gameObject.transform.position.x;
shotPosotion.y = this.gameObject.transform.position.y + 0.8f;
shotPosotion.z = this.gameObject.transform.position.z;
switch (typeshoot)
{
case 1:
GameObject instance = (GameObject)GameObject.Instantiate(shot, shotPosotion, this.gameObject.transform.rotation);
break;
case 2:
default: break;
}
computer = coolDown;
}
}
computer -= 1;
}
}
我作为加电代码的礼物是:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class powerUp : MonoBehaviour
{
private int computer=300;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void FixedUpdate()
{
if (computer <= 0) {
Destroy(this.gameObject);
}
computer -= 1;
}
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.name== "PlayerShip"){
other.gameObject.GetComponent<PlayerShooting>().typeshoot += 1;
Destroy(this.gameObject);
}
}
}