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();
playercollider = gameObject.GetComponent();
}
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
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”.
1 Like
Please take a look at this thread for future posts: Using code tags properly
It will insert code into the forums nicely and easier for us all to read 
Given that OP is using capital T Transform I doubt this very much 
I think this guy posted at least 2 threads. Pretty sure, in the other thread, that error was pointed out & resolved 
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);
}
}
}
Answer has already been provided. You assign playercollider but never actually use it for anything.