zoukankan      html  css  js  c++  java
  • unity, 鼠标与场景交点

    在鼠标与场景交点上放一个mark,并于1s后消失:

    新建一个空GameObject,命名为moushHitTest,添加下面脚本:

    using UnityEngine;
    using System.Collections;

    public class mouseHit : MonoBehaviour {
        public GameObject m_moushHitMarkPrefab;
        // Use this for initialization
        void Start () {
        
        }
        
        // Update is called once per frame
        void Update () {
        

            if (Input.GetMouseButtonDown (0)) {//left button down
                Ray camRay = Camera.main.ScreenPointToRay (Input.mousePosition);
                RaycastHit hitInfo;
                float camRayLength = 100f;
                bool isHit = Physics.Raycast (camRay,out hitInfo,camRayLength);
                if (isHit) {
                    Debug.Log(hitInfo.point);

              Debug.Log(hitInfo.transform.gameObject.name);
                    Object instance=Instantiate (m_moushHitMarkPrefab, hitInfo.point, Quaternion.identity);
                    instance.name="hitMark";
                    //about startCoroutine and yield: http://stackoverflow.com/questions/12932306/how-does-startcoroutine-yield-return-pattern-really-work-in-unity
                    StartCoroutine(delayDestroy(instance));

                }
            }

        }

        IEnumerator delayDestroy(Object instance){
            yield return new WaitForSeconds (1.0f);
            Destroy (instance);
        }

    }

  • 相关阅读:
    20155325 Exp7 网络欺诈防范
    20155325 Exp6 信息搜集与漏洞扫描
    从零开始学cookie(个人笔记)——一
    20155325 Exp5 MSF基础应用
    20155325 Exp4 恶意代码分析
    20155325 Exp3 免杀原理与实践
    20155325 Exp2 后门原理与实践
    20155323刘威良《网络对抗》Exp9 Web安全基础
    20155323刘威良《网络对抗》Exp8 Web基础
    20155323刘威良《网络对抗》Exp7 网络欺诈防范
  • 原文地址:https://www.cnblogs.com/wantnon/p/4525247.html
Copyright © 2011-2022 走看看