Edit:I’m very new to Unity and only just starting to grasp the basics here.
The idea is to have a button, which when pressed will slowly add speed onto the normal walk speed until a maximum running speed is reached. I’d tried this:
using UnityEngine;
using System.Collections;
public class Mario : MonoBehaviour {
public Transform mario;
public int marioMax = 20;
public int marioWalk = 7;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
//Mario can move left and right
mario.Translate (Vector3.right * marioWalk * Input.GetAxis ("Horizontal") * Time.deltaTime);
//a button can be pressed to make Mario run
if (Input.GetButtonDown ("KeyCode.LeftShift")) {
//if a button is pressed take mario's walking speed and slowly increase to it a maximum
mario.Translate (Vector3.right* ForceMode.Acceleration * Input.GetAxis("Horizontal") * Time.deltaTime);
}
But it doesn’t work, getting 3 errors:
Assets/Scripts/Mario.cs(26,50): error CS0019: Operator *' cannot be applied to operands of type
UnityEngine.Vector3’ and `UnityEngine.ForceMode’
Assets/Scripts/Mario.cs(26,31): error CS1502: The best overloaded method match for `UnityEngine.Transform.Translate(UnityEngine.Vector3)’ has some invalid arguments
Assets/Scripts/Mario.cs(26,31): error CS1503: Argument #1' cannot convert
object’ expression to type `UnityEngine.Vector3’
I think it’s because I can’t have vector3 and forcemode.acceleration together, but I could be wrong. I also know I’m not telling it that marioMax is the top speed, but have no idea how to implement that. Any ideas would be greatly appreciated.