簡體   English   中英

如何在 Unity (2D) 中使用鼠標移動 object?

[英]How to move an object with the mouse in Unity (2D)?

我正在為 android 制作二維統一游戲。 請幫我實現鼠標控制(以便可以從手機控制)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class qwe : MonoBehaviour
{
 public float direction = 1f; // initial direction
    public float speed = 20f; // speed of rotation

    void Update ()
    {
        float angle = transform.eulerAngles.z;
        if (angle > 180f) angle -= 360f;

        if ((angle < -40f) || (angle > 40f)) direction *= -1f; // reverse direction (toggles between 1 & -1)

        transform.Rotate (0, 0, speed * direction * Time.deltaTime);
    }
}

要使用鼠標輸入,您需要編寫

if (Input.GetMouseButtonDown(0))
{
    //your content here
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM