- Home /
Question by
Den D. · Jun 14, 2014 at 03:58 AM ·
addcomponent
Error in AddComponent
Below is my code but cannot figure it out what is the error occurring "Assets/Scripts/Circle.cs(22,49): error CS0201: Only assignment, call, increment, decrement, and new object expressions can be used as a statement"
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(GFGrid))]
public class Circle : MonoBehaviour {
private GFGrid levelGrid;
public GameObject objectToSpawn;
void OnGUI(){
Vector3 mousePos = Input.mousePosition;
mousePos.z = 5.0f;
mousePos = Camera.main.ScreenToWorldPoint(mousePos);
mousePos.y = 0.4f;
float top = buttonPosition == ButtonPosition.upLeft ? 0 : Screen.height - 50;
float left = buttonPosition == ButtonPosition.downRight ? Screen.width - 170 : 0;
if(GUI.Button(new Rect(left + 10, top - 10, 150, 50), "Try Another Level"))
{
GameObject obj = Instantiate(objectToSpawn, mousePos, Quaternion.identity) as GameObject;
obj.AddComponent<GFGrid>;
}
}
}
Comment
Best Answer
Answer by dagon · Jun 14, 2014 at 04:38 AM
line21 obj.AddComponent; -> obj.AddComponent();