New to C#, it’s pedantic. I’m used to Matlab. Basically `UnityEngine.Camera.main’ cannot be accessed with an instance reference, qualify it with a type name instead. In other words, it makes too much sense to be able to access the main camera by saying camera.main. How do I fix this?
using UnityEngine;
using System.Collections;
public class Building : MonoBehaviour {
public GameObject sphere1=null;
// Use this for initialization
void Start () {
sphere1=Instantiate(Resources.Load("Prefabs/prefab_sphere")) as GameObject;
}
// Update is called once per frame
void Update () {
var playerObject = GameObject.Find("Player");
var playerPos = (Vector3)playerObject.transform.position;
// var cam = camera.GetComponent(main);
var buildingPos = playerPos + camera.main.WorldToScreenPoint(Vector3.zero);
Debug.Log(playerPos);
if(Input.GetMouseButtonDown(0))
sphere1=Instantiate(Resources.Load("Prefabs/prefab_sphere"),buildingPos,Quaternion.identity) as GameObject;
}
}