|
Post by projectsolid on Apr 19, 2018 2:41:03 GMT
I want to increase the players running speed value under the Third Person Controller script when the player clicks a HUD button. Could you give me a starting point on how this can be achieved? I have no problem creating and positioning the button but where should the script be placed?
Thank you
|
|
|
Post by Legion on Apr 19, 2018 12:22:31 GMT
You can use: docs.unity3d.com/ScriptReference/UI.Button-onClick.htmlYou will have to create a boolean to alternate between the speeds each time you press the button. For example, we use this to alternate between running and walking: using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Invector.vCharacterController
{
public class WalkRunToggle : vMonoBehaviour {
public vThirdPersonMotor Player;
public bool ToggleWR = false;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown (KeyCode.CapsLock))
{
ToggleWR = !ToggleWR;
}
if (ToggleWR == true) {
Player.freeSpeed.walkByDefault = true;
Player.strafeSpeed.walkByDefault = true;
}
else if (ToggleWR == false)
{
Player.freeSpeed.walkByDefault = false;
Player.strafeSpeed.walkByDefault = false;
}
}
}
} The values you want to modify are at the end of vThirdPersonMotor.cs Surely there are simpler ways, anyway.
|
|
|
Post by projectsolid on Apr 19, 2018 20:21:38 GMT
Thanks for the feedback. My goal is to have a speed boost ability on a cool down. So when the player hits the button it increases run speed for X amount of time.
|
|