I am trying to create a simple script. I get this error : error CS0266: Cannot implicitly convert type int' to HelloWorld.Weaponsd’. An explicit conversion exists (are you missing a cast?) Can you please figure it out?
Code (This code gives out an error) :
using UnityEngine;
using System.Collections;
public class HelloWorld : MonoBehaviour {
public enum Weaponsd{None = 0, Pistol = 1, ShotGun = 2, Sniper = 3};
public Weaponsd Weapons ;
public int Ammos = 10;
public int Bullets = 1;
public int NumberOfBullets = 3;
void FireWeapon (int NumberOfBullets)
{
if (Weapons != 0) {
for (int i=0; i<NumberOfBullets; i++) {
if (Ammos > 0) {
Debug.Log ("Weapons Fired");
Ammos = Ammos - 1;
} else {
Debug.Log ("No Ammo");
}
}
} else {
Debug.Log("No Weapon");
}
}
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetKeyDown (KeyCode.Space)) {
if (Weapons = 1) {
FireWeapon(1);
}
}
}
}
Code(This Code doesn’t give out error):
using UnityEngine;
using System.Collections;
public class HelloWorld : MonoBehaviour {
public enum Weaponsd{None = 0, Pistol = 1, ShotGun = 2, Sniper = 3};
public Weaponsd Weapons ;
public int Ammos = 10;
public int Bullets = 1;
public int NumberOfBullets = 3;
void FireWeapon (int NumberOfBullets)
{
if (Weapons != 0) {
for (int i=0; i<NumberOfBullets; i++) {
if (Ammos > 0) {
Debug.Log ("Weapons Fired");
Ammos = Ammos - 1;
} else {
Debug.Log ("No Ammo");
}
}
} else {
Debug.Log("No Weapon");
}
}
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetKeyDown (KeyCode.Space)) {
if (Weapons != 0) {
FireWeapon(1);
}
}
}
}