Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

I can't find where I'm wrong

Discussion in 'Scripting' started by dago03, Dec 11, 2020.

  1. dago03

    dago03

    Joined:
    Dec 11, 2020
    Posts:
    4
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class playercontroller : MonoBehaviour
    6. {
    7.    
    8.     public float runSpeed = 5,0f;
    9.  
    10.     public float rotationSpeed = 200,0f;
    11.     private Animator anim;
    12.     public float x, y;
    13.  
    14.     // Start is called before the first frame update
    15.     void Start()
    16.     {
    17.      
    18.     }
    19.  
    20.     // Update is called once per frame
    21.     void Update()
    22.     {
    23.         x = Input.GetAxis("Horizontal");
    24.         y = Input.GetAxis("Vertical");
    25.  
    26.         transform.Rotate(0, x * Time.deltaTime * rotationSpeed, 0);
    27.         transform.translate(0, 0, y * Time.deltaTime * runSpeed);
    28.     }
    29. }
    30.  
     
  2. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    8,996
    is there some error message (screenshot / or copy from console window)?
     
  3. adamgolden

    adamgolden

    Joined:
    Jun 17, 2019
    Posts:
    1,498
    The problem is you're using commas instead of decimals:
    Code (CSharp):
    1. public float runSpeed = 5,0f;
    2. public float rotationSpeed = 200,0f;
    These should be:
    Code (CSharp):
    1. public float runSpeed = 5.0f;
    2. public float rotationSpeed = 200.0f;
     
    Bunny83 and mgear like this.
  4. dago03

    dago03

    Joined:
    Dec 11, 2020
    Posts:
    4
  5. Bunny83

    Bunny83

    Joined:
    Oct 18, 2010
    Posts:
    3,539
    When you get an error message you don't understand, please next time copy the error message from the console (you can select and copy the text in the lower half of the console when you're viewing an log message). Also please choose a descriptive title. The title will help no one who made the same mistake.
     
    JoNax97 likes this.
  6. dago03

    dago03

    Joined:
    Dec 11, 2020
    Posts:
    4
    [QUOTE = "polemical, post: 6611686, member: 3279967"] Il problema è che stai usando virgole invece di decimali:
    [code = CSharp] public float runSpeed = 5,0f;
    public float rotationSpeed = 200,0f; [/ code]
    Questi dovrebbero essere:
    [code = CSharp] public float runSpeed = 5.0f;
    public float rotationSpeed = 200.0f; [/ code] [/ QUOTE]

    ho corretto questo passaggio pero non ho ancora risolto
     
  7. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,780
    JoNax97 likes this.