I am making a 2.5D game and I am trying to make gun switching but the problem is that it doesn't work. There is no gun and there are no errors. What is wrong? (btw the array size is 3)
using UnityEngine;
using System.Collections;
public class InventorySelect : MonoBehaviour {
public GameObject[] inventoryOfGuns;
public GameObject player;
public Transform gunPos;
private int currentPosInArray;
void Awake ()
{
currentPosInArray = 0;
for(int i = 0; i < 3; i++)
{
GameObject gunInstance = (GameObject)Instantiate(inventoryOfGuns[i], gunPos.position, Quaternion.identity);
gunInstance.transform.parent = player.transform;
inventoryOfGuns[i].SetActive(false);
}
inventoryOfGuns[0].SetActive(true);
}
void Update ()
{
if(Input.GetKeyDown(KeyCode.E))
{
inventoryOfGuns[currentPosInArray].SetActive(false);
if(currentPosInArray == 2)
{
currentPosInArray = 0;
}
else
{
currentPosInArray++;
}
Debug.Log(currentPosInArray);
inventoryOfGuns[currentPosInArray].SetActive(true);
}
if(Input.GetKeyDown(KeyCode.Q))
{
inventoryOfGuns[currentPosInArray].SetActive(false);
if(currentPosInArray == 0)
{
currentPosInArray = 2;
}
else
{
currentPosInArray--;
}
Debug.Log(currentPosInArray);
inventoryOfGuns[currentPosInArray].SetActive(true);
}
}
}
↧