一、轿厢实例说明
- 楼层信息获取----包括楼层名和在各楼层时轿厢的位置;
- 轿厢上下移动----判断当前位置与目标点的距离,通过距离的正负来决定移动方向;
- 对重移动----对重的移动取决于轿厢,同时与轿厢应保持速度相同和运动方向相反;
- 开关层门与轿厢门----根据轿厢的状态以及轿厢当前位置判断是否停靠在某一层,播放动画;
- 轿厢AI----根据情况自动调用以上各部分。
二、需求分析
1、轿厢移动
- 定义列表变量----楼层信息
- 轿厢运动状态判断及运行----上行、下行、停止
1>楼层信息
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class StatusInfo : MonoBehaviour
{
public int people = 2;
public int maxPeople = 12;
public int amountPeople = 2;
public bool MovePeople()
{
int currentPeople = people + amountPeople;
if (people == 0 || currentPeople == people)
return false;
else if (currentPeople > maxPeople)
return false;
else
return true;
}
}
2>轿厢运动
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
public class Move : MonoBehaviour
{
public Transform[] points;
public WayLine line;
private int currentPointIndex=0;
public float MoveSpeed = 5;
public enum CarState
{
up,
down,
stop
}
public CarState carCurrentState = CarState.stop;
public CarState CarStateJudge(Vector3 point)
{
if (this.transform.position.y < point.y && (decimal)Vector3.Distance(this.transform.position, point) > 0.05m)
return carCurrentState = CarState.up;
else if (this.transform.position.y > point.y && (decimal)Vector3.Distance(this.transform.position, point) >