Unity数字孪生开发笔记——轿厢基本运动实现

一、轿厢实例说明

  • 楼层信息获取----包括楼层名和在各楼层时轿厢的位置;
  • 轿厢上下移动----判断当前位置与目标点的距离,通过距离的正负来决定移动方向;
  • 对重移动----对重的移动取决于轿厢,同时与轿厢应保持速度相同和运动方向相反;
  • 开关层门与轿厢门----根据轿厢的状态以及轿厢当前位置判断是否停靠在某一层,播放动画;
  • 轿厢AI----根据情况自动调用以上各部分。

二、需求分析

1、轿厢移动

  • 定义列表变量----楼层信息
  • 轿厢运动状态判断及运行----上行、下行、停止

1>楼层信息

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

/// <summary>
/// 定义状态信息类,定义轿厢人员信息,
/// </summary>
public class StatusInfo : MonoBehaviour
{
   
    /// <summary>
    /// 当前电梯人数
    /// </summary>
    public int people = 2;

    /// <summary>
    /// 电梯可承载人数最大值
    /// </summary>
    public int maxPeople = 12;

    /// <summary>
    /// 当前正在走进或走出电梯的人数
    /// </summary>
    public int amountPeople = 2;

    /// <summary>
    /// 人员流动
    /// </summary>
    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;

/// <summary>
/// 控制轿厢移动
/// </summary>
public class Move : MonoBehaviour
{
   
    public Transform[] points;
    public WayLine line;
    

    //当前路点索引
    private int currentPointIndex=0;

    public float MoveSpeed = 5;

    /// <summary>
    /// 定义轿厢运行状态
    /// </summary>
    public enum CarState
    {
   
        up,
        down,
        stop
    }
    public CarState carCurrentState = CarState.stop;

    /// <summary>
    /// 轿厢状态判断
    /// </summary>
    /// <param name="point">目标点坐标</param>
    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) >
  • 1
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 9
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

聪 ~smart

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值