zoukankan      html  css  js  c++  java
  • Unity3D之使用ITween制作自动漫游超简单

    ITween真的非常牛逼的东西,对于现在手头的程序里的一般机器的运动还有一些物体的有规律移动,包括第一人称视角的已知路线的自主漫游都可以用ITween来实现,既简单又实用。

    1,创建一个空对象,挂上ITween Path,根据需要设置Node Count的个数,然后再设置node内所有节点的位置

      

    2,比如我要做这个摄像机沿着这个路径进行漫游,那选中这个摄像机挂上PathAnimation.cs(不过这个是自已写的类)

      然后将PathAnimation的公共变量iTweenPath赋值

      

    3,这样的话我们就开始漫游了

      

     1 using UnityEngine;
     2 using System.Collections;
     3 using System.Collections.Generic;
     4 
     5 public class CarRunning_JX : MonoBehaviour
     6 {
     7     public List<PathAnimation> tiles = new List<PathAnimation>();
     8     public List<Transform> postions = new List<Transform>();
     9     public iTweenPath path_tuoChe;
    10     public iTweenPath path_tile;
    11     public PathAnimation tuoChe;
    12     // Use this for initialization
    13     void Start()
    14     {
    15         StartCoroutine(Running());
    16     }
    17 
    18     // Update is called once per frame
    19     void Update()
    20     {
    21 
    22     }
    23 
    24     IEnumerator Running()
    25     {
    26         tuoChe.path = path_tuoChe;
    27         tuoChe.Position = 0;
    28         yield return StartCoroutine(tuoChe.RotateTo(10, 0.424f, Quaternion.Euler(270f, 90f, 0)));
    29         yield return StartCoroutine(tuoChe.RotateTo(5, 0.5f, Quaternion.Euler(270f, 0f, 0)));
    30         yield return StartCoroutine(tuoChe.RotateTo(5, 1, Quaternion.Euler(270f, 0, 0)));
    31         for (int i = tiles.Count - 1; i >= 0; i--)
    32         {
    33             tiles[i].path = path_tile;
    34             tiles[i].Position = 0;
    35             tiles[i].path.nodes[0] = tiles[i].transform.position;
    36             tiles[i].path.nodes[tiles[i].path.nodes.Count - 1] = postions[tiles.Count - i - 1].transform.position;
    37             yield return StartCoroutine(tiles[i].RotateTo(3, 1, Quaternion.Euler(0, 180f, 270f)));
    38             yield return new WaitForSeconds(1);
    39         }
    40         yield return null;
    41     }
    42 }

    代码是随便挑了一节贴上的,大致的用法,很明了很简单。

    注:不过想在ITween Path上使物体匀速运动的话,一定要将路径的每一个节点之间的距离必须一致。

  • 相关阅读:
    外校培训前三节课知识集合纲要(我才不会告诉你我前两节只是单纯的忘了)
    floyd算法----牛栏
    bfs开始--马的遍历
    (DP 线性DP 递推) leetcode 64. Minimum Path Sum
    (DP 线性DP 递推) leetcode 63. Unique Paths II
    (DP 线性DP 递推) leetcode 62. Unique Paths
    (DP 背包) leetcode 198. House Robber
    (贪心 复习) leetcode 1007. Minimum Domino Rotations For Equal Row
    (贪心) leetcode 452. Minimum Number of Arrows to Burst Balloons
    (字符串 栈) leetcode 921. Minimum Add to Make Parentheses Valid
  • 原文地址:https://www.cnblogs.com/cathytong/p/4686028.html
Copyright © 2011-2022 走看看