I am a newbie here~pls hlp
I have a problem with the script
it appear error like this ‘‘Can’t add script behaviour TP_Controller.You need to fix all compile error in all script first’’
And at an error appear too under the unity~Too many character in character literal
Anyone can hlp me to shorten it or help?
This:
using UnityEngine;
using System.Collections;
public class TP_Controller : MonoBehaviour
{
public static CharacterController CharacterController;
public static TP_Controller Instance;
void Awake()
{
CharacterController = GetComponent('CharacterController') as CharacterController;
Instance = this;
}
void Update()
{
if (Camera.mainCamera == null)
return;
GetLocomotionInput();
TP_Motor.Instance.UpdateMotor();
}
void GetLocomotionInput()
{
var deadZone = 0.1;
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 (0, 0, Input.GetAxis('Horizontal'), 0, 0);
}
}
And another script here:
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 Awake()
{
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;
// Multiply 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);
}
}
Just looking it over “by eye”, I see the following:
Remove the “.” in “.deadZone” in both of the following snippets:
if (Input.GetAxis('Vertical') > deadZone ll Input.GetAxis('Vertical') < .deadZone)
if (Input.GetAxis('Horizontal') > deadZone ll Input.GetAxis('Horizontal') < .deadZone)
Here, “0.I” should be “0.1”
var deadZone = 0.If;
Here, the trailing “)” should be a “}”
public Vector3 MoveVector { get; set; )
Here, you’re missing a trailing semi-colon:
SnapAlignCharacterWithCamera()
Here, you need to remove the space within “| |”
If (MoveVector.x != 0 l l MoveVector.z != 0)
That should be a good start. When writing scripts, syntax is critical. It can’t be “close”, it has to be exactly as expected. Also, when you post code, use the board’s code tags, as it makes it much more readable.
Well, as I said, I only quickly scanned your code by eye (which is somewhat difficult to do as you didn’t wrap your source in code tags). I’m sure there are likely other problems. You’ll just need to fix them one at a time until things are working as expected.
One more thing, I didn’t notice in your original code since it’s missing code tags…
You’re welcome. Take some time to study the changes I made, as there were lots of “little” things wrong. Once you get some experience with the syntax, you should be able to fix these things yourself.
Ok,i seen that u can just look through my script ‘‘by eye’’ so fast and find out the problem
Mayb u do lots of study on script
This is the first time i started making game
So i will try to learn some from wat u taught
Thanks!