Search Unity

Bug with my script

Discussion in 'Scripting' started by leovideo599, Oct 22, 2017.

  1. leovideo599

    leovideo599

    Joined:
    Oct 22, 2017
    Posts:
    6
    I everybody, I have a bug in my script but i don't find it

    This is my script :

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class Charactermotor : MonoBehaviour {


    Animation animations;


    public float walkSpeed;
    public float runSpeed;
    public float turnSpeed;


    public string inputFront;
    public string inputBack;
    public string inputLeft;
    public string inputRight;

    public Vector3 JumpSpeed;
    CapsuleCollider playercollider;

    void Start()
    {
    animations = gameObject.GetComponent<Animation>();
    playercollider = gameObject.GetComponent<CapsuleCollider>();
    }


    void Update()
    {

    if (Input.GetKey(inputFront))
    {
    Transform.Translate(0, 0, walkSpeed * Time.deltaTime);
    animations.Play("walk");
    }


    if (Input.GetKey(inputBack))
    {
    Transform.Translate(0, 0, -(walkSpeed / 2) * Time.deltaTime);
    animations.Play("Walk");
    }


    if (Input.GetKey(inputLeft))
    {
    Transform.Rotate(0, -turnSpeed * Time.deltaTime, 0);
    }



    if (Input.GetKey(inputRight))
    {
    Transform.Rotate(0, turnSpeed * Time.deltaTime, 0);
    }

    }
    }


    And this is my bug :Assets/SpartanKing/character motor.cs(22,21): warning CS0414: The private field `Charactermotor.playercollider' is assigned but its value is never used


    Thanks you in advance for your help
     
  2. Mad-hamster

    Mad-hamster

    Joined:
    Jun 20, 2014
    Posts:
    2
    That's only a warning and your script works regardless. The issue is exactly what the warning says: "The private field is assigned but its value is never used".
     
    Ryiah likes this.
  3. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
  4. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    Given that OP is using capital T Transform I doubt this very much :)
     
  5. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    I think this guy posted at least 2 threads. Pretty sure, in the other thread, that error was pointed out & resolved :)
     
  6. leovideo599

    leovideo599

    Joined:
    Oct 22, 2017
    Posts:
    6
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class Charactermotor  : MonoBehaviour {
    6.  
    7.  
    8.     Animation animations;
    9.  
    10.    
    11.     public float walkSpeed;
    12.     public float runSpeed;
    13.     public float turnSpeed;
    14.  
    15.    
    16.     public string inputFront;
    17.     public string inputBack;
    18.     public string inputLeft;
    19.     public string inputRight;
    20.  
    21.     public Vector3 JumpSpeed;
    22.     CapsuleCollider playercollider;
    23.  
    24.     void Start()
    25.     {
    26.         animations = gameObject.GetComponent<Animation>();
    27.         playercollider = gameObject.GetComponent<CapsuleCollider>();
    28.     }
    29.  
    30.    
    31.     void Update()
    32.     {
    33.  
    34.         if (Input.GetKey(inputFront))
    35.         {
    36.             transform.Translate(0, 0, walkSpeed * Time.deltaTime);
    37.             animations.Play("walk");
    38.         }
    39.  
    40.  
    41.         if (Input.GetKey(inputBack))
    42.         {
    43.             transform.Translate(0, 0, -(walkSpeed / 2) * Time.deltaTime);
    44.             animations.Play("Walk");
    45.         }
    46.  
    47.  
    48.         if (Input.GetKey(inputLeft))
    49.         {
    50.             transform.Rotate(0, -turnSpeed * Time.deltaTime, 0);
    51.         }
    52.  
    53.  
    54.  
    55.         if (Input.GetKey(inputRight))
    56.         {
    57.             transform.Rotate(0, turnSpeed * Time.deltaTime, 0);
    58.         }
    59.  
    60.     }
    61. }
    62.  
    63.  
     
  7. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    Answer has already been provided. You assign playercollider but never actually use it for anything.
     
  8. leovideo599

    leovideo599

    Joined:
    Oct 22, 2017
    Posts:
    6
    ok thank you