hejsa or hello Unity
can anyone help me, with a 3rd-Person Controller with, C# Scripts
i have follow the, 3d Buzz 3rd-Person Controller with C# tutorials
i add the TP_Controller Scrip and the TP_Motor Scrip to the Object
i don´t get any Error and character don´t move Nothing´s Happening
and if i copy TP_Controller Scrip and the TP_Motor Scrip to a new
project i get a Error
(NullReferenceException: Object reference not set to an instance of an object)
i will really appreciate if anyone can help me,
using UnityEngine;
using System.Collections;
public class TP_Controller: MonoBehaviour
{
public static CharacterController CharacterController;
public static TP_Controller Instance;
void Awaker()
{
CharacterController = GetComponent("CharacterController") as CharacterController;
Instance = this;
}
void Update()
{
if (Camera.mainCamera == null)
return;
GetLocomotionInput();
TP_Motor.Instance.UpdateMotor();
}
void GetLocomotionInput()
{
var deadZone = 0.1f;
TP_Motor.Instance.MoveVector = Vector3.zero;
if (Input.GetAxis("Vertical") > deadZone || Input.GetAxis("Vertical") < -deadZone)
TP_Motor.Instance.MoveVector += new Vector3(0, 0, Input.GetAxis("Vertical"));
if (Input.GetAxis("Horizontal") > deadZone || Input.GetAxis("Horizontal") < -deadZone)
TP_Motor.Instance.MoveVector += new Vector3(Input.GetAxis("Horizontal"), 0, 0);
}
}
using UnityEngine;
using System.Collections;
public class TP_Motor : MonoBehaviour
{
public static TP_Motor Instance;
public float MoveSpeed = 10f;
public Vector3 MoveVector { get; set; }
void Awaker()
{
Instance = this;
}
public void UpdateMotor()
{
SnapAlignCharacterwithCamera();
ProcessMotion();
}
void ProcessMotion()
{
// Transform MoveVector to world space
MoveVector = transform. TransformDirection(MoveVector);
// Normalize MoveVector if Magnitude > 1
if (MoveVector.magnitude > 1)
MoveVector = Vector3.Normalize(MoveVector);
// Mulitply MoveVector by MoveSpeed
MoveVector *= MoveSpeed;
// Mulitply MoveVector by DeltaTime
MoveVector *= Time.deltaTime;
// Move the Character in world space
TP_Controller.CharacterController.Move(MoveVector);
}
void SnapAlignCharacterwithCamera()
{
if (MoveVector.x != 0 || MoveVector.z != 0)
{
transform.rotation = Quaternion.Euler(transform.eulerAngles.x,
Camera.mainCamera.transform.eulerAngles.y,
transform.eulerAngles.z);
}
}
}