Blogger Information
Blog 95
fans 0
comment 11
visits 248848
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
Unity3d物体移动到鼠标左键点击处
龍__遇见彩虹的博客
Original
1572 people have browsed it

using UnityEngine;
using System.Collections;

/*
 *物体移动到鼠标左键点击处
 */

public class PlayerMovePos : MonoBehaviour {

    private bool finish = true;
    private Vector3 pos;

    // Use this for initialization
    void Start () {
    
    }
    
    // Update is called once per frame
    void Update () {

        //物体每次移动一定距离到鼠标点击处
        //if (Input.GetMouseButtonDown(0))
        //{
        //    Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        //    RaycastHit hit = new RaycastHit();
        //    if (Physics.Raycast(ray, out hit))
        //    {
        //        pos = hit.point;
        //        pos.y = 20f;
        //        finish = false;
        //    }
        //}

        //if (Input.GetMouseButtonUp(0))
        //{
        //    finish = true;
        //}







        //if (!finish)
        //{
        //    Vector3 offset = pos - transform.position;
        //    transform.position += offset.normalized * 100 * Time.deltaTime;
        //    if (Vector3.Distance(pos, transform.position) < 1f)
        //    {
        //        transform.position = pos;
        //        finish = true;
        //    }
        //}


        //物体直接出现在鼠标左键点击的位置
        //if (Input.GetMouseButtonDown(0))
        //{
        //    Vector3 screenpos = Input.mousePosition;
        //    Ray ray = Camera.main.ScreenPointToRay(screenpos);
        //    RaycastHit hitinfo = new RaycastHit();
        //    if (Physics.Raycast(ray, out hitinfo))
        //    {
        //        pos = hitinfo.point;
        //        transform.position = new Vector3(pos.x,transform.position.y, pos.z);
        //    }
        //}
    }
}



使用请去掉注释!!!

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post