Các phím điều hướng

 avatar
user_0729670
csharp
2 years ago
1.0 kB
7
Indexable
Never
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class DanH : MonoBehaviour
{
    // Start is called before the first frame update
    public float Speed1 = 1.0f;
    public float Speed2 = 2.0f;


    void Start()
    {
        Debug.Log("hello world");


    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetKey(KeyCode.RightArrow))
        {
            transform.position += new Vector3(Speed1, 0, 0);
        }
        if (Input.GetKey(KeyCode.LeftArrow))
        {
            transform.position -= new Vector3(Speed1, 0, 0);
        }
        if (Input.GetKey(KeyCode.UpArrow))
        {
            transform.position += new Vector3(0, Speed1, 0);
        }

        if (Input.GetKey(KeyCode.DownArrow))
        {
            transform.position -= new Vector3(0, Speed1, 0);
        }

        if (Input.GetMouseButtonDown(0))
        {
            transform.Translate(0, Speed2, 0);
        }

    }
}