繁体   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