Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

delay in shooting

hi i want to make a delay in the gun script any help




using System.Collections;

using System.Collections.Generic;

using UnityEngine;


public class gun : MonoBehaviour

{

  public float damage = 10;

  public float range = 100;

  public Camera cam;

  public GameObject sound;

  // Update is called once per frame

  void Update()

  {

    if (Input.GetButtonDown("Fire1"))

    {

      shoot();

       

      sound.SetActive(true);

      Invoke("sd", 2);

    }

  }


  void shoot()

  {

    RaycastHit hit;

    if(Physics.Raycast(cam.transform.position, cam.transform.forward, out hit, range))

    {

      Debug.Log(hit.transform.name);

      enemy em = hit.transform.GetComponent<enemy>();

      if (em != null)

      {

        em.takeDamge(damage);

         

      }


    }


  }


  void sd()

  {

    sound.SetActive(false);

  }

}

Sign In or Register to comment.