using UnityEngine;
using System.Collections;
/// <summary>
/// Camera script. This Script is attached to the player. It causes the camera to continuously follow the camera head.
/// </summary>
public class CameraScript : MonoBehaviour {
// Variables Start
private Camera MyCamera;
private Transform CameraHeadTransform;
// Variables End
// Use this for initialization
void Start ()
{
MyCamera = Camera.main;
CameraHeadTransform = Transform.FindChild ("Camera Head");
}
// Update is called once per frame
void Update ()
{
// Make the camera follow the player's CameraHeadTransform
MyCamera.Transform.position = CameraHeadTransform.position;
MyCamera.transform.rotation = CameraHeadTransform.Rotation;
}
This is my code for my game, I’m brand new to unity and C# coding, I’m currently doing a indepth tutorial on how to create a multiplayer fist person shooter, the tutorial is telling me to use the “CameraHeadTransform = Transform.FindChild (“Camera Head”) ;” to state my child camera head within my player erm perfab? I’m not sure what the terms are so forgive me if this is confusing.
Once i save the code within mono it automatically updated inside unity but when i try and test the code ingame i get an error message saying: “Assets/Standard Assets/Scripts/CameraScript.cs(16,49): error CS0120: An object reference is required to access non-static member `UnityEngine.Transform.FindChild(string)'” now i double and triple checked but everything seems to be the same as the tutorial is saying.
Thanks for your time and help!