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. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

blend tree scripting to activate through keys?

Discussion in 'Scripting' started by Jeepster, May 7, 2018.

  1. Jeepster

    Jeepster

    Joined:
    Jan 23, 2014
    Posts:
    401
    Hi,

    I'm trying to activate the floats in my blend tree with an : if(Input.GetKey...) but it's not working.

    The tutorial I was following had this script, but it doesn't work with W,S,A,D:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class BlendtreeCntrl : MonoBehaviour {
    6.  
    7.     private Animator _animator;
    8.  
    9.    
    10.  
    11.     // Use this for initialization
    12.     void Start () {
    13.  
    14.         _animator = GetComponent<Animator>();
    15.        
    16.     }
    17.    
    18.     // Update is called once per frame
    19.     void Update () {
    20.  
    21.         if (_animator == null) return;
    22.  
    23.         var x = Input.GetAxis("Horizontal");
    24.         var y = Input.GetAxis("Vertical");
    25.  
    26.  
    27.         //if (Input.GetKey(KeyCode.W))
    28.         // {
    29.  
    30.         Move(x,y);
    31.  
    32.     }
    33.  
    34.     private void Move(float x, float y)
    35.     {
    36.         _animator.SetFloat("VelX", x);
    37.         _animator.SetFloat("VelY", y);
    38.  
    39.    
    40.     }
    41. }
    Can anyboy tell me how I can activate the floats in my blend tree on Input.GetKey?
     
  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
  3. Jeepster

    Jeepster

    Joined:
    Jan 23, 2014
    Posts:
    401
    Both the horizontal/vertical input in the input manager and the animator are active/present. It doesn't make sense to me. Could the code be wrong?
     
  4. Jeepster

    Jeepster

    Joined:
    Jan 23, 2014
    Posts:
    401
    Oops :D Nevermind, I forgot to add the script to my character hahaha, no wonder it didn't work
     
    LeftyRighty likes this.