miércoles, 19 de abril de 2023

script en c# de unity para hacer disparos tiro a tiro o en rafagas con el raton o con el teclado;

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

public class DISPARAESCUPITAJOSBOTONDERECHORATON : MonoBehaviour
{
   


    [SerializeField] private AudioClip sndNewDamage;
    [SerializeField] private AudioClip sndCrashWarning;
    [SerializeField] private AudioClip sndHasDamageWarning;
    [SerializeField] private AudioClip sndFueldLow;
    public Rigidbody projectile;
    public float speed = 1;//originallllllllllllllllllllllllllllllllllllllllllllll

    //public float speed = 0.1f;
    // Update is called once per frame
    void Update()
    {
        //if (Input.GetKey (KeyCode.Mouse1)){///ORIGINAL 8-7-22
        //if (Input.GetButtonDown("Fire3")){///TIRO A TIRO


       // if (Input.GetButtonDown("Fire2"))
      
       // {///TIRO A TIRO


          //  if (Input.GetButton("Fire2"))
           // {//AMETRALLADORA




           // if (Input.GetButton("Fire2"))
          //  {//AMETRALLADORA






                //if (Input.GetButtonDown("Fire2")){///TIRO A TIRO
                //if (Input.GetButton ("Fire1"))////// AMETRALLADORA AMETRAYADORA
                //if (Input.GetKey (KeyCode.M)){
                //if (Input.GetButtonUp("Fire1"))/////TIRO A TIRO

                //    if (Input.GetMouseButtonDown(3))
                //if (Input.GetKey (KeyCode.Mouse1)){







                    //if (Input.GetKey (KeyCode.Space)) {// escupe rafagas

                   if (Input.GetKeyDown("space"))
                                                   {// escupe de 1 en 1










                //if (Input.GetKey (KeyCode.Mouse1)){///ORIGINAL 8-7-22
                //    if ((Input.GetKey (KeyCode.I)) && (Input.GetKey (KeyCode.O))) {////////funciona al apretar las 2 teclas a la vez  I O ////
                //    if (Input.GetKey (KeyCode.O)) {

                //{
                Rigidbody p = Instantiate(projectile, transform.position, transform.rotation);
            p.velocity = transform.forward * speed;


        }
    }
}