My helicopter can't fire sequently.

I am making a game with Unity.But I can’t find true fire methods. How can I do?

Please provide more information about what you want to do. Your question is very vague.

I want to when I press any button,helicopter has to fire to targets sequently.

What kind of targets are we talking about? How do we know which objects are valid targets? Is this a 2d game? 3d? What kind of weapon is the helicopter firing? Were the targets acquired and sequenced by some previous process?

Have you try anything?

3 Likes

Targets are 3D game objects. That is no significant. Just , When I press any button back to back,the helicopter has to fire without interrupt.

Clearly, I change some codes.For instance I added Destroy function. That was caused to break processing.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class HelikopterSaldirisi : MonoBehaviour
{
    public Transform hedef;//Hedef nesne belirlendi.
    public GameObject mermi;//Mermi belirlendi.
    public AudioSource sesKaynagi;
    void Awake()
    {
        sesKaynagi = GetComponent<AudioSource>(); //Ses kaynağını da ekledik.
    }
    void Update()
    {
        if(Input.GetKey(KeyCode.F))
        {
            Atis();
        }
    }
    void Atis()
    {
        if (mermi != null)
        {
            Vector3 yon = (hedef.position - transform.position);
            float k = (yon.x / yon.z); //yatay eksen ile düşey eksenin eğimi hesaplandı.

            float donus = Mathf.Atan(k) * Mathf.Rad2Deg;
            GameObject mermiler = Instantiate(mermi, transform.position, Quaternion.identity) as GameObject; //Örneklendirme yapıldı.
            mermiler.transform.rotation = Quaternion.Euler(0f, donus, 0f); //Böyle yönelecek.
            mermiler.GetComponent<Rigidbody>().AddForce(yon * 5.0f);
            GameObject rr = mermiler.gameObject;
            rr.transform.position = mermiler.transform.position; //Aynı yere atadım.
            mermiler.SetActive(false);


           

            sesKaynagi.Play();//Ses kaynağı çalıştırılacak.
        }
    }
   
   
}

Variables’ name is Turkish.

Still don’t quite understand what you’re doing here, and the issue you’re having. What do you mean by “true fire methods?”

Sorry.I want to type true Fire() function.

Depends on what you wanna do here… and what you want to do in the fire()… So you gotta explain a little more, I’m not good with code yet, but with the logic that I can help.

Firstly,When I press to something button,main game object has to fire towards target.
Then,Either game object’s missile hits target or neither, Missile has to be destroyed inside five minutes.

So It seems like you already have a button to activated it, upon pressing it should be moving the missle forward * delta.Time, you would also need to instantiate a missile prefab and where it would spawn from so you can create an empty prefab as it’s spawn point. You’d need to access that spawn point and set the missle’s instantiation there. Then you can do an if statement where the missile would have this trigger collider where if it hits another collider and it is the target it would destroy the target or do damage to it. If it doesn’t collide with anything you can use you can use waitforseconds for it to destroy itself in the given time.

Thanks @mgrekt

1 Like