Current code in NodeControllerRevCsharp.cs:
using UnityEngine;
using System.Collections;
public class CameraNode{
public Vector3 position;
public float range;
public CameraNode(Vector3 position, float range){
this.position = position;
this.range = range;
}
}
public class NodeControllerRevCsharp : MonoBehaviour {
public float range;
void OnDrawGizmosSelected() {
Gizmos.color = Color.red;
Gizmos.DrawWireSphere (transform.position, range);
}
void Start () {
CameraNode myNode = new CameraNode(transform.position, range);
gameObject.Find("Main Camera").GetComponent(CameraControllerRevCsharp).cameraNodes.push(myNode);
//GameObject.Find("Main Camera").GetComponent(CameraControllerRevCsharp).cameraNodes.push(myNode);
//Camera.main.GetComponent(CameraControllerRevCsharp).cameraNodes.push(myNode);
//gameObject.Find(Camera.main).GetComponent(CameraControllerRevCsharp).cameraNodes.push(myNode);
}
}
Resultant error message:
Assets/Scripts/NodeControllerRevCsharp.cs(26,28):
error CS0176: Static member
`UnityEngine.GameObject.Find(string)’
cannot be accessed with an instance
reference, qualify it with a type name
instead
C# newbie having a little trouble accessing my Main Camera in code - I’ve got this working in JS, so I assume the solution to this is just extraordinary ignorance. I’ve looked up the error on UnityAnswers ( Search results for 'CS0176' - Unity Discussions ) and either the existing answers are unhelpful or I just don’t understand 'em.
Previous attempts to solve the issue can be found near the end of the code, commented out. All yielded a further rats nest of errors.
Would anybody care to hazard a solution? And perhaps a bug-finding methodology so I’m not constantly bothering the good people of Unity Answers? =)
Thanks for reading,
–Rev
And that works. Perfectly. Thanks! --Rev
– Reverend-Speed