最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

史上最全Unity3D教程

2022-07-05 08:50 作者:屑貓貓耳  | 我要投稿

c#代碼

p140

EnemyMotor

using System.Collections;

using System.Collections.Generic;

using Unity.VisualScripting;

using UnityEngine;

using UnityEngine.SocialPlatforms;

/// <summary>

/// 敵人馬達(dá)器,提供移動(dòng)、旋轉(zhuǎn)、尋路功能

/// </summary>

public class EnemyMotor : MonoBehaviour

{

??private Vector3 startingPoint;

??private Vector3 destination;

??private WayLine wayLine;

??private Vector3[] points;

??private EnemySpawn enemySpawn;

??private bool isMove;

??public float nextTime;

??private int i = 0;

??/// <summary>

??/// 前行

??/// </summary>

??public void MovementForward()

??{

????this.transform.Translate(0, 0, (float)0.02);

??}


??/// <summary>

??/// 注視旋轉(zhuǎn)

??/// </summary>

??/// <param name="targetPoint">需要注視的目標(biāo)點(diǎn)</param>

??public void targetPoint(Vector3 targetPoint)

??{

????this.transform.LookAt(targetPoint);

??}

??/// <summary>

??/// 尋路,沿路線移動(dòng)

??/// </summary>

??/// <returns></returns>

??public bool Pathfinding()

??{

????targetPoint(points[i]);

????MovementForward();

????//你可以試試==0,會(huì)發(fā)生什么

????if (Vector3.Distance(this.transform.position, points[i]) <=0.02)

??????i++;

????if (i >= 4)

??????return false;

????else

??????return true;

??}

??// Start is called before the first frame update

??void Start()

??{

????isMove=true;

????startingPoint = this.transform.position;

????nextTime = 1;

????enemySpawn =Object.FindObjectOfType<EnemySpawn>();

????wayLine = enemySpawn.FingWayLine();

????points = wayLine.GetWayPoints();

??}


??// Update is called once per frame

??void Update()

??{

????if (isMove)

????{

??????isMove = Pathfinding();

????}

??}

}


using System;

using System.Collections;

using System.Collections.Generic;

using System.Drawing;

using System.Reflection;

using UnityEngine;

/// <summary>

/// 敵人生成器

/// </summary>

public class EnemySpawn : MonoBehaviour

{

??private WayLine[] wayLines;

??private System.Random random;

??private int firstNum;

??private int finallyNum;

??public int nextTime;

??// Start is called before the first frame update

??//private Vector3 point;

??//private Vector3[] points;

??//private WayLine wayLine;

??void Start()

??{

????//wayLine=FingWayLine();

????//points = wayLine.Points;

????//for (int i = 0; i < points.Length; i++)

????//{

????//point = points[i];

????//Debug.Log(point);

????//}

??}

??/// <summary>

??/// 找路線,沒(méi)做不重復(fù)

??/// </summary>

??public WayLine FingWayLine()

??{

????wayLines = this.transform.GetComponentsInChildren<WayLine>();

????random = new System.Random();

????firstNum = 0;

????finallyNum = wayLines.Length;

????int usedNum = random.Next(firstNum, finallyNum);

????wayLines[usedNum].IsUseable = false;

????Debug.Log(wayLines[usedNum]);

????//if (usedNum == firstNum)

??????//firstNum += 1;

????//else if (usedNum == finallyNum)

??????//finallyNum -= 1;

????return wayLines[usedNum];

??}

}


using System;

using System.Collections;

using System.Collections.Generic;

using System.Drawing;

using UnityEngine;

/// <summary>

/// 路線類

/// </summary>

public class WayLine : MonoBehaviour

{

??private Vector3[] Points;

??public bool IsUseable;

??private Transform[] PointsTF;

??private Vector3[] newPoints;

??// Start is called before the first frame update

??void Start()

??{

????PointsTF = this.transform.GetComponentsInChildren<Transform>();

????Points = new Vector3[PointsTF.Length];

????newPoints = new Vector3[PointsTF.Length - 1];

????IsUseable=true;

??}

??/// <summary>

??/// 找路點(diǎn)

??/// </summary>

??/// <returns>Vector3[] 路點(diǎn)數(shù)組</returns>

??public Vector3[] GetWayPoints()

??{

????for (int i = 0; i < PointsTF.Length; i++)

????{

??????Points[i] = PointsTF[i].position;??

????}

????for (int i = 0; i < newPoints.Length; i++)

????{

??????newPoints[i] = Points[i + 1];

????}

????return newPoints;

??}



敵人可以用Cube代替


史上最全Unity3D教程的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
民县| 定边县| 呼图壁县| 大渡口区| 临泽县| 措美县| 东山县| 枣阳市| 舞钢市| 米泉市| 江源县| 齐齐哈尔市| 屏东市| 开原市| 德惠市| 平塘县| 阳谷县| 宜宾市| 泉州市| 车险| 克东县| 合水县| 汽车| 酒泉市| 青田县| 合阳县| 福州市| 青河县| 盈江县| 穆棱市| 工布江达县| 永新县| 香格里拉县| 阿克苏市| 高陵县| 清水河县| 房产| 霸州市| 凤翔县| 万荣县| 罗江县|