zoukankan      html  css  js  c++  java
  • Unity3D-射线效果

    基于airplane_02 下面新建 Line Renderer

    将上面的几个地方设置下

    添加Script脚本:

    脚本代码为:

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public class AirPlane : MonoBehaviour
    {
        public LineRenderer lineRender;
    
        public Transform gunPoint;
        // Start is called before the first frame update
        void Start()
        {
            lineRender = GetComponent<LineRenderer>();
        }
    
        // Update is called once per frame
        void Update()
        {
            if (Input.GetMouseButton(0))
            {
                lineRender.enabled = true;
                lineRender.SetPosition(0, gunPoint.position);
                Ray ray = Camera.main.ScreenPointToPay(Input.mousePosition);
                RaycastHit hit;
                if (Physics.Raycast(ray, out hit))
                {
                    lineRender.SetPosition(1, hit.point);
                }
            }
            else
            {
                lineRender.enabled = false;
            }
    
        }
    }
    
    
    

    在airplane_02下 Create Empty ,gunPoint

    运行可看到效果:

  • 相关阅读:
    css相关
    杂题
    vuesheng生命周期
    box-sizing
    js正则学习
    浏览器加载解析过程
    Sass学习笔记
    jQuery与原生js实现banner轮播图
    jq-animate实现返回顶部效果
    jq-animate
  • 原文地址:https://www.cnblogs.com/ButterflyEffect/p/10225714.html
Copyright © 2011-2022 走看看