Problem with script

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);
		}
	}

THX

Put it in CODE brackets or it didnt happen :stuck_out_tongue:

wat is a code bracket
sry i am newbie

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.

Jeff

what a trailing semi-colon?

A semi-colon character “;” at the end of the statement.

So this:

SnapAlignCharacterWithCamera()

should be…

SnapAlignCharacterWithCamera();

Hmmm…it look like it doesnt work
i chged all the character u stated but still the same

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…

If (MoveVector.x != 0 l l MoveVector.z != 0)

The above should be:

If (MoveVector.x != 0 || MoveVector.z != 0)

Wondering wat the problem

What errors are you getting now? (and did you see my edit above)?

Ya i saw it n edited it but…still the same
so i think thr shud somemore problem on the script

I get the error ‘‘Can’t add script behaviour TP_Controller.You need to fix all compile error in all script first’’

by the way i chg all my script to code tag
Edit:Updated all the script with the problem u stated

OK, the code tags make things much easier to see. Now, I see that you have:

l l

in several places where you should have:

||

In addition, what compile errors are you getting?

it say too many character in character literal

i will keep updating my script with the problem u stated here

OK, I plugged both scripts into VS and fixed the compile errors. There were lots of syntax related issues…

While I can’t speak for whether the logic is correct or not, the scripts will now compile:

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);
        }
    }
}

and…

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"));
	
	}
}

OMG!!
THANK YOU VERY MUCH
U HELP ME ALOT :smile:

And does VS mean Visual Studio?

I think i need the program for future scripting
I will try to find it

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.

Yes.

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! :smile: