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. Dismiss Notice

Assets/NewBehaviourScript.cs(19,19): error CS1502:

Discussion in 'Scripting' started by petea, May 16, 2014.

  1. petea

    petea

    Joined:
    Nov 29, 2013
    Posts:
    55
    Assets/NewBehaviourScript.cs(19,19): error CS1502: The best overloaded method match for `UnityEngine.Input.GetKeyDown(string)' has some invalid arguments.

    Assets/NewBehaviourScript.cs(25,19): error CS1503: Argument `#1' cannot convert `object' expression to type `string'

    Assets/NewBehaviourScript.cs(30,38): error CS0117: `UnityEngine.KeyCode' does not contain a definition for `d'

    Whote problem?

    using UnityEngine;
    using System.Collections;

    public class CubeMove : MonoBehaviour
    {
    public float moveSpeed = 3f;
    // Use this for initialization
    void Start()
    { }
    // Update is called once per frame
    void Update()
    {
    //Moves Forward and back along z axis //Up/Down
    if (Input.GetKeyDown(KeyCode.w))
    {
    //transform.Translate(Vector3.forward+1);
    Debug.Log('w');
    }
    if (Input.GetKeyDown(KeyCode.s))
    {
    Debag.log('s');
    //transform.Translate(Vector3.forward - 1);
    }
    //Moves Left and right along x Axis //Left/Right
    if (Input.GetKeyDown(KeyCode.a))
    {
    Debug.Log('a');
    //transform.Translate(Vector3.right + 1);
    }
    if (Input.GetKeyDown(KeyCode.d))
    {
    Debug.Log('d');
    // transform.Translate(Vector3.right - 1);
    }
    // float h = Input.GetAxis("horizontal");
    // float v = Input.GetAxis("Vertical");
    // transform.position = new Vector3(h, v, 0) * moveSpeed * Time.deltaTime;
    }
    }
     
    Last edited: May 16, 2014
  2. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    8,937
  3. petea

    petea

    Joined:
    Nov 29, 2013
    Posts:
    55
    SORRY
    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class CubeMove : MonoBehaviour
    5. {
    6.         public float moveSpeed = 3f;
    7.         // Use this for initialization
    8.         void Start()
    9.     {   }
    10.     // Update is called once per frame
    11.     void Update()
    12.     {
    13.         //Moves Forward and back along z axis //Up/Down
    14.         if (Input.GetKeyDown(KeyCode.W))
    15.         {
    16.             transform.Translate(Vector3.forward+1);
    17.             Debug.Log('w');
    18.         }
    19.         if (Input.GetKeyDown(KeyCode.S))
    20.         {
    21.             Debug.Log('s');
    22.             transform.Translate(Vector3.forward - 1);
    23.         }
    24.         //Moves Left and right along x Axis //Left/Right
    25.         if (Input.GetKeyDown(KeyCode.A))
    26.         {
    27.             Debug.Log('a');
    28.             transform.Translate(Vector3.right + 1);
    29.         }
    30.         if (Input.GetKeyDown(KeyCode.D))
    31.         {
    32.             Debug.Log('d');
    33.             transform.Translate(Vector3.right - 1);
    34.         }
    35.         //        float h = Input.GetAxis("horizontal");
    36.   //      float v = Input.GetAxis("Vertical");
    37.     //    transform.position = new Vector3(h, v, 0) * moveSpeed * Time.deltaTime;
    38.    }
    39. }
    40.  
     
  4. Epictickle

    Epictickle

    Joined:
    Aug 12, 2012
    Posts:
    431
    Code (csharp):
    1.  
    2. using UnityEngine;
    3.  
    4. using System.Collections;
    5.  
    6.  
    7.  
    8. public class CubeMove : MonoBehaviour
    9.  
    10. {
    11.  
    12.         public float moveSpeed = 3f;
    13.  
    14.         // Use this for initialization
    15.  
    16.         void Start()
    17.  
    18.     {   }
    19.  
    20.     // Update is called once per frame
    21.  
    22.     void Update()
    23.  
    24.     {
    25.  
    26.         //Moves Forward and back along z axis //Up/Down
    27.  
    28.         if (Input.GetKeyDown(KeyCode.W))
    29.  
    30.         {
    31.  
    32.             transform.Translate(Vector3.forward * (moveSpeed * Time.deltaTime));
    33.  
    34.             Debug.Log("w");
    35.  
    36.         }
    37.  
    38.         if (Input.GetKeyDown(KeyCode.S))
    39.  
    40.         {
    41.  
    42.             Debug.Log("s");
    43.  
    44.             transform.Translate(-Vector3.forward * (moveSpeed * Time.deltaTime));
    45.  
    46.         }
    47.  
    48.         //Moves Left and right along x Axis //Left/Right
    49.  
    50.         if (Input.GetKeyDown(KeyCode.A))
    51.  
    52.         {
    53.  
    54.             Debug.Log("a");
    55.  
    56.             transform.Translate(Vector3.right * (moveSpeed * Time.deltaTime));
    57.  
    58.         }
    59.  
    60.         if (Input.GetKeyDown(KeyCode.D))
    61.  
    62.         {
    63.  
    64.             Debug.Log("d");
    65.  
    66.             transform.Translate(-Vector3.right * (moveSpeed * Time.deltaTime));
    67.  
    68.         }
    69.  
    70.         //        float h = Input.GetAxis("horizontal");
    71.  
    72.   //      float v = Input.GetAxis("Vertical");
    73.  
    74.     //    transform.position = new Vector3(h, v, 0) * moveSpeed * Time.deltaTime;
    75.  
    76.    }
    77.  
    78. }
    79.  
    If you want to use Input.GetAxis(), look here:
    http://docs.unity3d.com/Documentation/ScriptReference/Input.GetAxis.html

    it's really simple.
     
  5. petea

    petea

    Joined:
    Nov 29, 2013
    Posts:
    55
    sorry, not work in scene. Whote work this error
     

    Attached Files:

    • $345.png
      $345.png
      File size:
      33.5 KB
      Views:
      923
  6. petea

    petea

    Joined:
    Nov 29, 2013
    Posts:
    55
    thank you
     
  7. JamesElvin

    JamesElvin

    Joined:
    Sep 19, 2013
    Posts:
    33
    You need to rename the script to CubeMove. Where it says 'public class CubeMove' is the name of the script file.
     
  8. petea

    petea

    Joined:
    Nov 29, 2013
    Posts:
    55
    thank you/