Hi.
I’m making Android FPS but I don’t know how to change “if (Input.GetKeyDown(“number”))” to button.
Can someone help?
This is my code if needed:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WeaponSwitcher : MonoBehaviour
{
public GameObject weapon01;
public GameObject weapon02;
public GameObject weapon03;
// Use this for initialization
void Start ()
{
weapon01.SetActive(false);
weapon02.SetActive(false);
weapon03.SetActive(true);
}
// Update is called once per frame
void Update ()
{
if (Input.GetKeyDown("1"))
{
weapon01.SetActive(true);
weapon02.SetActive(false);
weapon03.SetActive(false);
}
if (Input.GetKeyDown("2"))
{
weapon01.SetActive(false);
weapon02.SetActive(true);
weapon03.SetActive(false);
}
if (Input.GetKeyDown("3"))
{
weapon01.SetActive(false);
weapon02.SetActive(false);
weapon03.SetActive(true);
}
}
}
You have a game object in the canvas that is the button for switching weapons, right?
Does is have a “Button” component that looks like this: Screenshot by Lightshot
I have buttons to meant to change weapon but they wont work because android doesnt have 1,2 and 3. Script to change weapon is stored in controller and only way to change weapon is using keyboard and I want to use button I made to change weapon
I’m from Poland and I’m 14 years old so Im barelly good in english