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

(35,27) The name Keycode does not exist in current context

Discussion in 'Scripting' started by Voodin, Mar 14, 2019.

  1. Voodin

    Voodin

    Joined:
    Apr 19, 2018
    Posts:
    48
    Heres the entire script so far
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class PlayerMethods : MonoBehaviour
    6. {
    7.   /*this is a work in progress, so make sure to keep making it okay!
    8.   Changelog:
    9.   v1.1 Movement works, Jumping doesnt
    10.   */
    11.     public static void Move(Transform trans,float horzSpeed,float vertSpeed)
    12.     {
    13.     //movement goes here
    14.     float movHorz = Input.GetAxis("Horizontal");
    15.     float movVert = Input.GetAxis("Vertical");
    16.  
    17.     Vector3 movement = new Vector3(movHorz*horzSpeed,0.0f,movVert*vertSpeed);
    18.     trans.position += movement;
    19.     }
    20.  
    21.     public static void Jump(Transform trans,string button,float height)
    22.     {
    23.           //jump goes here
    24.           if(Input.GetButtonDown("Jump")||Input.GetKeyDown(KeyCode.JoystickButton0))
    25.           {
    26.             Vector3 movement = new Vector3(0.0f,Mathf.MoveTowards(trans.position.y, height, 0.1f * Time.deltaTime),0.0f);
    27.             trans.position += movement;
    28.             Debug.Log("jumping");
    29.           }
    30.  
    31.     }
    32.     public static void Interact(Component target)
    33.     {
    34.       //interaction stuff goes here
    35.       if(Input.GetKeyDown(Keycode.JoyStickButton2)||Input.GetKeyDown(Keycode.E))
    36.       {
    37.         //interactable objects will have an OnInteract() method
    38.         //target.OnInteract();
    39.       }
    40.        
    41.     }
    42.     public static void Attack1()
    43.     {
    44.       //basic attack goes here
    45.     }
    46. }
    why does Keycode work on line 24 but not on line 35? I didnt have this error until I added the code after my jump method
     
    athavirdaus likes this.
  2. drcrck

    drcrck

    Joined:
    May 23, 2017
    Posts:
    328
    because it's KeyCode, not Keycode
     
    Krus_765, bplc, athavirdaus and 6 others like this.
  3. Voodin

    Voodin

    Joined:
    Apr 19, 2018
    Posts:
    48
    well i feel silly now
     
    OpMakesGames and monkeyphobia like this.
  4. paulspray

    paulspray

    Joined:
    Jul 28, 2019
    Posts:
    3
    yep, massive forehead palm here too....
     
    OpMakesGames likes this.
  5. N0oneI1

    N0oneI1

    Joined:
    Jun 19, 2022
    Posts:
    1
    Tho probably my own face palm giving me a less headache then solving it on my own. Thanks guy!