newbie trouble assigning value to vector3

Hello,

i have been trying to assign a value to the y axis but every time i do that it give me compilation error says Unexpected symbol ‘=’

here is the code that has the problem

Vector3 dircetion = transform.localEulerAngles ;
direction.y = 180.0f;

and here is all of the code

using UnityEngine;
using System.Collections;

public class player : MonoBehaviour {

    public  float speed = 1;

    bool stat_digimon = false;
    Animator animator;
    float moving = 4;
    public Transform body;
    Vector3 dircetion = transform.localEulerAngles ;
    direction.y = 180.0f;


   
    // Use this for initialization
    void Start () {
        animator = GetComponent<Animator> ();

    }
   
    // Update is called once per frame
    void Update () {


        CharacterController Controller = GetComponent<CharacterController>();
        Vector3 vertical = transform.TransformDirection (Vector3.forward);
        Vector3 horizontal = transform.TransformDirection (Vector3.right);
        animator.SetFloat("Speed",speed);
        if (Input.GetAxis ("Vertical")>0||Input.GetAxis ("Vertical")<0
            || Input.GetAxis ("Horizontal")>0||Input.GetAxis ("Horizontal")<0)
        {
            animator.SetFloat ("Speed", moving);
            Controller.Move ((vertical * (speed * Input.GetAxis ("Vertical")) * Time.deltaTime));
            Controller.Move ((horizontal * (speed * Input.GetAxis ("Horizontal")) * Time.deltaTime));
        }
        else
        {
            animator.SetFloat("Speed",speed);
       
        }

        if (Input.GetKeyDown (KeyCode.Escape)) {

            stat_digimon = !stat_digimon;
        }

    }


    void OnGUI()
    {

        if (stat_digimon == true) {
                    GUI.Box (new Rect (200, 250, 300, 300),"Test");
                    GUI.Button(new Rect(150,200,100,100),"Test");       
                }

           

    }
    void LateUpdate(){
        // Rotate the Character to match the direction he/she is going
        if(Input.GetAxis("Vertical") == 0){
            if(Input.GetAxis("Horizontal") > 0){
                transform.localEulerAngles.y = new Vector3(0f,180f,0f);
                //transform.localEulerAngles = dircetion;
            }else if(Input.GetAxis("Horizontal") < 0){
                body.localEulerAngles.y = 0;
            }
        }else if(Input.GetAxis("Vertical") > 0){
            if(Input.GetAxis("Horizontal") > 0){
                body.localEulerAngles.y = 135;
            }else if(Input.GetAxis("Horizontal") < 0){
                body.localEulerAngles.y = 45;
            }
        }else if(Input.GetAxis("Vertical") < 0){
            if(Input.GetAxis("Horizontal") == 0){
                body.localEulerAngles.y = -90;
            }else if(Input.GetAxis("Horizontal") > 0){
                body.localEulerAngles.y = -135;
            }else if(Input.GetAxis("Horizontal") < 0){
                body.localEulerAngles.y = -45;
            }
        }
    }
}

On line 67 you ask to set a float value into a vector3

thnx man :slight_smile: fixed

1 Like

It’s the difference between “direction” and “dircetion”. Watch those typos.