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

    运行可看到效果:

  • 相关阅读:
    paramiko
    Oracle 正则
    格式化输出
    pl/sql
    logging-----日志模块
    linux学习笔记01
    PHP-HTML-MYSQL表格添加删除
    费了好大劲做的比较好看的表单
    HTML框架
    两天笔记
  • 原文地址:https://www.cnblogs.com/ButterflyEffect/p/10225714.html
Copyright © 2011-2022 走看看