Я пытаюсь включить пулю моего космического корабля, когда беру что-то вроде подарка. Я много пробовал, но ничего не получается :( Кто-нибудь может мне помочь, пожалуйста
Я пытался, но этот код, но он никогда не работает для меня, и я ищу во многих веб-сайтах, просто я понимаю, что тогда мой корабль уничтожается, так как он уничтожен, когда он поражает врагов, любая помощь по моему вопросу, пожалуйста:)
мой код корабля:
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);
}
}
}