can somebody help

im coding a weapon script to control stuff like ammo amount,reloading and other things but im getting this error

Assets/scripts/weapon.cs(8,26): error CS0031: Constant value 1' cannot be converted to a int’

here is the code what is causing this

using UnityEngine;
using System.Collections;

public class weapon : MonoBehaviour {

public int rounds = 17;
public int curentrounds = 17;
public int animspeed = 1.0;
public GameObject gun;
public AnimationClip fire;
public AnimationClip reload;


	// Use this for initialization
	void Start () {
	animspeed = AnimationState.speed = animspeed;
	
	
	}
	
	// Update is called once per frame
	void Update () 
		{	
			if (Input.GetMouseButtonDown(0))
			{	
				animation.Play (fire);
				curentrounds -=1;
				
			if (curentrounds <= 0)
								;
				animation.Play (reload);
				animspeed = 0.5f; 
			}	
			else
			{	
			if (Input.GetKeyDown(KeyCode.R))
				animation.Play (reload);
				 animspeed = 1f;
			}
	}
}

a little info i wanted to punish the player for not reloading when they had low ammo,so if they let the gun dry fire it will slow the reloading animation

thank you for your time and effort in advance

2 Answers

2

Edited Answer…:

void Start() {

    animation["AnimationName"].speed = animspeed;

}

and make sure animspeed variable is:

public float animspeed = 1.0f;

sadly neither a double or a float work for me

the errors i get are the same as i have stated on chris_dlala's post

this is after changing line 8

ive tried this code with both a float and a double and the only one that slightly works is animation[reload].speed = animspeed; i get less errors with that but its still giving me Assets/scripts/weapon.cs(17,17): error CS1503: Argument #1' cannot convert UnityEngine.AnimationClip' expression to type string' and Assets/scripts/weapon.cs(24,35): error CS1502: The best overloaded method match for UnityEngine.Animation.Play(UnityEngine.PlayMode)' has some invalid arguments on multiple lines and that is with a float

Hi, the problem (error) is in the following line:

public int animspeed = 1.0;

You have defined an integer (whole number) but you have assigned a decimal, to fix it either change the animSpeed type to a float or change the assignment to a whole number but I think you probably want this:

public float animspeed = 1.0f;

Hope that helps =D

thank you for the answer but sadly it doesn't help i get a tone of errors after changing to a float

ok so instead of just saying it didn't work here are the errors i get Assets/scripts/weapon.cs(16,36): error CS0120: An object reference is required to access non-static member UnityEngine.AnimationState.speed' Assets/scripts/weapon.cs(26,43): error CS1502: The best overloaded method match for UnityEngine.Animation.Play(UnityEngine.PlayMode)' has some invalid arguments i also get this on lines 31 and 37 Assets/scripts/weapon.cs(26,43): error CS1503: Argument #1' cannot convert UnityEngine.AnimationClip' expression to type `UnityEngine.PlayMode' also on lines 31 and 37

You might find it did help, but now you have a new set of errors. eg.. this line doesn't make sense for a start. animspeed = AnimationState.speed = animspeed;