Question by
unity_I3C164np0h-H5A · Oct 06, 2020 at 10:20 AM ·
movementmovement scriptmove an object
How to make the player move faster after I press and hold the button? Because now it's only making something like a short jump,How to make player move faster after press and hold the button?
using System.Collections.Generic; using UnityEngine;
public class Move : MonoBehaviour {
public float speed;
private Vector2 moveAmount;
private Rigidbody2D rb;
private Vector2 targetMoove;
private void Start()
{
rb = GetComponent<Rigidbody2D>();
}
private void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
transform.Translate(new Vector2(0, 1) * speed * Time.deltaTime);
}
else
{
transform.Translate(new Vector2(0, 0.5f) * Time.deltaTime);
}
}
private void FixedUpdate()
{
rb.MovePosition(rb.position + moveAmount * Time.fixedDeltaTime);
}
}
Comment