- Home /
Why is my code not working?
Why is this code not working. I have not used UnityAnswers before. I am using C#:-
using UnityEngine;
using System.Collections;
public class SwapObjects : MonoBehaviour
{
public GameObject Stone;
public GameObject Cobble;
public GameObject Dirt;
public GameObject Grass;
void Update ()
{
if(EventType.KeyDown(KeyCode.U))
{
Stone.SetActive(true);
Cobble.SetActive(false);
Dirt.SetActive(false);
Grass.SetActive(false);
}
if(EventType.KeyDown(KeyCode.I))
{
Stone.SetActive(false);
Cobble.SetActive(true);
Dirt.SetActive(false);
Grass.SetActive(false);
}
if(EventType.KeyDown(KeyCode.O))
{
Stone.SetActive(false);
Cobble.SetActive(false);
Dirt.SetActive(true);
Grass.SetActive(false);
}
if(EventType.KeyDown(KeyCode.P))
{
Stone.SetActive(false);
Cobble.SetActive(false);
Dirt.SetActive(false);
Grass.SetActive(true);
}
}
}
The 4 errors I am getting is
Assets/SwapObjects.cs(13,30): error CS0119: Expression denotes a value, where a method group was expected
Assets/SwapObjects.cs(20,30): error CS0119: Expression denotes a value, where a method group was expected
Assets/SwapObjects.cs(27,30): error CS0119: Expression denotes a value, where a method group was expected
Assets/SwapObjects.cs(34,30): error CS0119: Expression denotes a value, where a method group was expected
All the same. What am I doing wrong?
Answer by Graham-Dunnett · Jun 26, 2013 at 08:52 PM
Events in Unity happen inside the OnGUI()
function. Use `Input.GetkeyDown()` to check for key presses inside Update()
.
Your answer

Follow this Question
Related Questions
Problem creating a cutscene event in c# 2 Answers
Instantiating Prefab error C# 1 Answer
Javascript communication to C#, Error CS0119, method group vs variable 0 Answers
error CS0119 1 Answer