- Home /
GUI.Label Error
I'm currently having problems fixing these two errors. I understand what is causing the error but I'm not sure what i can do to stop it from doing so. Any help is appreciated.
Edit: The use of "public UnityEngine.GUIStyle style = null;" worked. No errors when I used that.
1 Assets/Scripts/BulletFireScript.cs(39,21): error CS1502: The best overloaded method match for UnityEngine.GUI.Label(UnityEngine.Rect, string, UnityEngine.GUIStyle)' has some invalid arguments #2 Assets/Scripts/BulletFireScript.cs(39,21): error CS1503: Argument
#3' cannot convert GUIStyle' expression to type
UnityEngine.GUIStyle'
using UnityEngine;
using System.Collections;
public class BulletFireScript: MonoBehaviour {
public Transform Bullet;
int shots = 5;
int maxshots = 0;
//public Font myFont;
public Rect position = new Rect(200, 15, 150, 25);
public string text = "Ammo: ";
public GUIStyle style = null;
// Use this for initialization
void Start () {
Screen.lockCursor = true;
}
// Update is called once per frame
void Update () {
if (Input.GetButtonDown ("Fire1") && shots > maxshots) {
Instantiate (Bullet, transform.position, transform.rotation);
shots--;
}
else if(Input.GetKeyDown(KeyCode.R))
{
shots=5;
}
}
private void OnGUI(){
//GUI.skin.font = myFont;
//GUI.Label(new Rect(20,20,100,20), "TEST" + shots);
GUI.Label(position, text, style);
}
}
I don't get any errors when I compile the same script.
You can try to be explicit with the GUIStyle declaration, like "public UnityEngine.GUIStyle style = null;"
Likewise, if you have a custom class of your own called "GUIStyle", I would recommend you rename it.
If all else fails, I know it sounds dumb, but try restarting Unity. :/
Your answer
Follow this Question
Related Questions
ArgumentException: Getting control 1's position... 0 Answers
Error on GUIStyle.Draw 2 Answers
Unsupported int type GUIStyle 1 Answer
Cant load image into my game 2 Answers
Object reference not set to... 1 Answer