Please Fix newbie
If I remove the joystick the SpeedButton works if the joystick script is there the SpeedButton does not work. I don't need forward motion cause I have made a script that made the character move forward. deleting or not that auto running script does not affect this script. what I want are both joystick and speed button work. please help thanks
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class SpeedupSkill : MonoBehaviour { protected SpeedButton SpeedButton; public float cooldownTime = 7; private float nextFireTime = 0; protected Joystick joystick; // Use this for initialization void Start() {
SpeedButton = FindObjectOfType<SpeedButton>();
joystick = FindObjectOfType<FloatingJoystick>();
}
// Update is called once per frame
void Update()
{
var rigidbody = GetComponent<Rigidbody>();
rigidbody.velocity = new Vector3(joystick.Horizontal * 100f,
rigidbody.velocity.y);
if (SpeedButton.Pressed && Time.time > nextFireTime)
{
rigidbody.velocity += Vector3.forward * 100f;
nextFireTime = Time.time + cooldownTime;
}
}
}
Answer by janjoeljanjoel · Aug 01, 2020 at 02:52 PM
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class SpeedupSkill : MonoBehaviour { protected SpeedButton SpeedButton; public float cooldownTime = 7; private float nextFireTime = 0; protected Joystick joystick; // Use this for initialization void Start() {
SpeedButton = FindObjectOfType<SpeedButton>();
joystick = FindObjectOfType<FloatingJoystick>();
}
// Update is called once per frame
void Update()
{
var rigidbody = GetComponent<Rigidbody>();
if (SpeedButton.Pressed && Time.time > nextFireTime)
{
rigidbody.velocity += Vector3.forward * 100f;
nextFireTime = Time.time + cooldownTime;
}
if (Input.GetKey(KeyCode.A))
{
transform.Translate(Vector3.left * Time.deltaTime * 30f, Space.Self); //LEFT
}
if (Input.GetKey(KeyCode.D))
{
transform.Translate(Vector3.right * Time.deltaTime*30f,Space.Self); //RIGHT
}
}
} never mind I fix it i just need to add two new buttons and delete the joystick
Your answer
Follow this Question
Related Questions
Java to c# fall damage 1 Answer
How to add information to an instantiated object 0 Answers
Setting Animation on Scene Load 1 Answer