Смена оружия по нажиманию на кнопку
Добавлено: 25 авг 2019, 20:03
Я захотел сделать скрипт, чтобы при нажимании на кнопку он менял оружие
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WeaponChange : MonoBehaviour
{
public GameObject weapon1;
public GameObject weapon2;
public GameObject weapon3;
public int MaxWeapon = 3;
private int Guns;
// Update is called once per frame
void Update()
{
if(Guns == 0)
{
weapon1.SetActive(true);
weapon2.SetActive(false);
weapon3.SetActive(false);
}
if (Guns == 1)
{
weapon1.SetActive(false);
weapon2.SetActive(true);
weapon3.SetActive(false);
}
if (Guns == 2)
{
weapon1.SetActive(false);
weapon2.SetActive(false);
weapon3.SetActive(true);
}
if(Guns <= 0)
{
Guns = 0;
}
if(Guns >= MaxWeapon)
{
Guns = MaxWeapon;
}
if (Input.GetKeyDown ("E") > 0f)
{
Guns += 1;
}
if (Input.GetKeyDown ("Q") < 0f)
{
Guns -= 1;
}
}
}
Но вот в место этого, юнити выдаёт мне ошибку
Assets\WeaponChange.cs(42,13): error CS0019: Operator '>' cannot be applied to operands of type 'bool' and 'float'
И
Assets\WeaponChange.cs(46,13): error CS0019: Operator '<' cannot be applied to operands of type 'bool' and 'float'
Я знаю, что ошибки очень глупые, но я попытался сделать свой первый огромный скрипт, можете сказать, как мне его изменить, чтобы он стал работать?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WeaponChange : MonoBehaviour
{
public GameObject weapon1;
public GameObject weapon2;
public GameObject weapon3;
public int MaxWeapon = 3;
private int Guns;
// Update is called once per frame
void Update()
{
if(Guns == 0)
{
weapon1.SetActive(true);
weapon2.SetActive(false);
weapon3.SetActive(false);
}
if (Guns == 1)
{
weapon1.SetActive(false);
weapon2.SetActive(true);
weapon3.SetActive(false);
}
if (Guns == 2)
{
weapon1.SetActive(false);
weapon2.SetActive(false);
weapon3.SetActive(true);
}
if(Guns <= 0)
{
Guns = 0;
}
if(Guns >= MaxWeapon)
{
Guns = MaxWeapon;
}
if (Input.GetKeyDown ("E") > 0f)
{
Guns += 1;
}
if (Input.GetKeyDown ("Q") < 0f)
{
Guns -= 1;
}
}
}
Но вот в место этого, юнити выдаёт мне ошибку
Assets\WeaponChange.cs(42,13): error CS0019: Operator '>' cannot be applied to operands of type 'bool' and 'float'
И
Assets\WeaponChange.cs(46,13): error CS0019: Operator '<' cannot be applied to operands of type 'bool' and 'float'
Я знаю, что ошибки очень глупые, но я попытался сделать свой первый огромный скрипт, можете сказать, как мне его изменить, чтобы он стал работать?