Click here to Skip to main content
15,885,141 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have two guns and two different functions for it. i want that gun to shoot which I have picked. but even other guns is shooting that I haven't picked
so someone please solve this issue.

C#
public class weapon  : MonoBehaviour
{

    public Transform firepoint1; //this is a firepoint
    public Transform firepoint2; //this is a firepoint

    public GameObject bulletprefab;
    public GameObject f;
    public GameObject f1;

    // Start is called before the first frame update
    void Start()
    {
        Rigidbody2D rb = GetComponent();
        rb.constraints = RigidbodyConstraints2D.FreezeRotation;

    }

    // Update is called once per frame
    void Update()
    {
        
         
    }
     void shoot()
    {
     
        //shoot
        
        
            Instantiate(bulletprefab, firepoint1.position, firepoint1.rotation);




    }
    void shoot1()
    {
        
            Instantiate(bulletprefab, firepoint2.position, firepoint2.rotation);


    }
    void OnTriggerStay2D(Collider2D trig)
    {
     


        if (f.gameObject != null && gameObject.tag =="player")
        {
           

            if (Input.GetButtonDown("Fire1"))
            {
                shoot();
            }
      
        }
        if (f.gameObject != null && gameObject.tag == "player")
        {
            

            if (Input.GetButtonDown("Fire1"))
            {
                shoot1();
            }
        }
    }
}


What I have tried:

i have tried lots of things so someone please solve this issue
Posted
Updated 29-Oct-21 9:00am
v2
Comments
RedDk 29-Oct-21 14:58pm    
Yo Bro, this looks suspiciously like a programming question. Maybe it's better if you post it here: https://www.codeproject.com/Lounge.aspx
Member 15329613 29-Oct-21 16:03pm    
Programming questions do not go in the Lounge.
Dave Kreskowiak 29-Oct-21 15:31pm    
OK, so how do you track which gun is "picked"?
[no name] 29-Oct-21 16:25pm    
If you have "guns", you should have something called "guns"; if you want anyone else to understand your code.
Lemons and Giggles 30-Oct-21 4:56am    
Bro can you just give me a script to understand how can I do it I have 2 gun one button if a condition match the one will work another will no work or shoot

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900