zoukankan      html  css  js  c++  java
  • Unity3D 画线插件 Vectrosity 画一个一直循环的正弦函数曲线

    直接贴代码

     public Material myMaterisl;
        float fx;//曲线最左边的X坐标
        float fy;//曲线趋于直线时y轴坐标
        float fyMax = 0f;//曲线最高点
        float fyContunt = 1f;//曲线于y轴坐标的交点
        VectorLine energyLine;
        Vector2[] energyLinePoints;
        float timer;
        float energyLevel = 4f;
        void Start()
        {
            fx = 0f;
            fy = 125f;
    
            energyLinePoints = new Vector2[100];
            energyLine = new VectorLine("Energy", energyLinePoints, myMaterisl, 5f, LineType.Continuous);
            fnSetEnergyLinePointsMove();
        }
        void fnSetEnergyLinePoints()
        {
            for (int i = 0; i < energyLinePoints.Length; i++)
            {
                float x = Mathf.Lerp(70f, 470f, (0.0f + i) / energyLinePoints.Length);//设置点X的坐标
                energyLinePoints[i].y = fy * (1f + Mathf.Sin(x) * 0.1f * energyLevel);
                energyLinePoints[i] = new Vector2(x, energyLinePoints[i].y);//第一次设置点x,y的坐标
    
            }
        }
        void fnSetEnergyLinePointsMove()
        {
            for (int i = 0; i < energyLinePoints.Length; i++)
            {
                float x = Mathf.Lerp(70f, 470f, (i + .0f) / energyLinePoints.Length);//设置点X的坐标
                energyLinePoints[i] = new Vector2(x, fy);//第一次设置点x,y的坐标
            }
        }
    
    
        void Update()
        {
    
        }
    
    
        void FixedUpdate()
        {
            //让曲线向左运动
    
            int i;
            for (i = 0; i < energyLinePoints.Length - 1; i++)
            {
                energyLinePoints[i].y = energyLinePoints[i + 1].y;//让当前点的y值=它右面点的y值,就是曲线向左移动
            }
            timer += Time.deltaTime * Mathf.Lerp(10.0f, 20.0f, energyLevel);
            energyLinePoints[i].y = fy * (1f + Mathf.Sin(timer) * .1f * energyLevel);
          
    
        }
        void LateUpdate()
        {
            energyLine.Draw();
        }
    

    把脚本添加到摄像机上
    运行效果如图:

  • 相关阅读:
    常用模块——hashlib模块
    day21作业
    常用模块——configparser模块
    常用模块——xml模块
    常用模块——json模块
    常用模块——shelve模块
    常用模块——pickle模块
    shutil模块
    常用模块——os模块
    简易nagios安装出现的问题及解决方法
  • 原文地址:https://www.cnblogs.com/YDoubleC/p/6203735.html
Copyright © 2011-2022 走看看