Hi, I have created a C# script for my game in unity 2019.2.0f1 and when it has finished compiling, i. Tried to drop a GameObject to it to assign it as a GameObject variable, but it doesn’t let me do that, I cannot assign any GameObject to it… Also when I tried : GameObject.setActive(true); it doesn’t let me , I don’t have the option to do it…
Show us your code (please use code tags). then perhaps describe a Little bit more how you attached the script to a game object (not the other way round). Maybe describe also what you expect to see, what you see instead, and why you think that is not what you want. I’m sure we can sort this one out in no time at all ![]()
We drop script to game object in inspector window not other way round
Here is the code This is not the only script im having the problem:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DoorManager : MonoBehaviour
{
public Key Requiredkey;
public Key TakenKey;
string KeyName;
public bool IsLocked;
public GameObject TDoor;
bool IsOpen;
public GameObject OpenDoorDisp;
private void Start()
{
if (IsLocked == true)
{
KeyName = Requiredkey.KeyName;
}
}
public void Open()
{
if (IsLocked == true)
{
if (TakenKey.KeyName == KeyName)
{
if (IsOpen == true)
{
this.gameObject.GetComponent<Animation>().Play("DoorClose");
}
else
{
this.gameObject.GetComponent<Animation>().Play("DoorOpen");
}
IsOpen = !IsOpen;
}
else
{
//Display Error
}
}
else
{
if (IsOpen == true)
{
this.gameObject.GetComponent<Animation>().Play("DoorClose");
}
else
{
this.gameObject.GetComponent<Animation>().Play("DoorOpen");
}
IsOpen = !IsOpen;
}
}
public bool PlayerNear = false; //Triggers when player is inside given range
public void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "Player")
{
PlayerNear = true;
}
}
public void OnTriggerExit(Collider other)
{
if (other.gameObject.tag == "Player")
{
PlayerNear = false;
//Display is hidden
}
}
private void Update()
{
if (PlayerNear == true)
{
if (Input.GetKeyDown(KeyCode.E))
{
Open();
}
}
}
}
So what is the problem? Your imagery seems to indicate some issues with autocompletion, hardly a Unity issue.
Found the problem, actually i had a script named GameManager and for whatever reason, its namespace was GameObject
