- Home /
Footstep Scipt, (What is wrong?)
using UnityEngine; using System.Collections;
public class Footsteps : MonoBehaviour {
public AudioClip[] footsteps;
public float nextFoot;
IEnumerator Start ()
{CharacterController controller = GetComponent<CharacterController> ();
while (true) {
if(controller.isGrounded && controller.velocity.magnitude > 0.3F)
{
audio.PlayOneShot(Footsteps[Random.Range(0, Footsteps.Length)]);
yield return new WaitForSeconds(nextFoot);
}
else
{
yield return 0;
}
any help would be appreciated.
I am trying to get a footsteps script, but I have been having no luck I keep getting this error. Assests/Footsteps.cs(17.51): error CS0119: expression denotes a 'type', where a 'variable','value', or 'method group' was expected
Not quit sure what to do I am a beginner at Unity.
Answer by robertbu · Mar 28, 2014 at 12:31 AM
When I try and compile your code, I don't get that specific error. Is is possible you have a Footsteps class in your project? Anyway, the only issue I see is on line 12. You want 'footsteps' with a lower case 'f' in the two places you use 'Footsteps' in this line of code. Youalso want to return null instead of '0'.
using UnityEngine;
using System.Collections;
public class Bug25a : MonoBehaviour {
public AudioClip[] footsteps;
public float nextFoot;
IEnumerator Start () {
CharacterController controller = GetComponent<CharacterController> ();
while (true) {
if(controller.isGrounded && controller.velocity.magnitude > 0.3F)
{
audio.PlayOneShot(footsteps[Random.Range(0, footsteps.Length)]);
yield return new WaitForSeconds(nextFoot);
}
else
{
yield return null;
}
}
}
}
Answer by RaptureFace · Jul 20, 2014 at 03:13 PM
I got the answer but in JavaScript... If its any help here it is:
#pragma strict
var walk : AudioClip;
var run : AudioClip;
var isWalking : boolean = false;
var isRunning : boolean = false;
function Update()
{
GetState();
PlayAudio();
}
function GetState()
{
if ( Input.GetAxis( "Horizontal" ) || Input.GetAxis( "Vertical" ) )
{
if ( Input.GetKey( "left shift" ) || Input.GetKey( "right shift" ) )
{
// Running
isWalking = false;
isRunning = true;
}
else
{
// Walking
isWalking = true;
isRunning = false;
}
}
else
{
// Stopped
isWalking = false;
isRunning = false;
}
}
function PlayAudio()
{
if ( isWalking )
{
if ( audio.clip != walk )
{
audio.Stop();
audio.clip = walk;
}
if ( !audio.isPlaying )
{
audio.Play();
}
}
else if ( isRunning )
{
if ( audio.clip != run )
{
audio.Stop();
audio.clip = run;
}
if ( !audio.isPlaying )
{
audio.Play();
}
}
else
{
audio.Stop();
}
}
I did a modification of my script to include a sprint timer : http://answers.unity3d.com/questions/596645/limited-sprint.html
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
FPS Footstep Audio Plays Too Quickly 1 Answer
Footsteps Script for Running and Walking 3 Answers
Footsteps? 4 Answers