国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > C# > 正文

Unity實(shí)現(xiàn)物體左右移動(dòng)效果

2020-01-24 00:01:40
字體:
供稿:網(wǎng)友

本文實(shí)例為大家分享了Unity實(shí)現(xiàn)物體左右移動(dòng)效果的具體代碼,供大家參考,具體內(nèi)容如下

效果如下

代碼:

using UnityEngine;using System.Collections; //Add this script to the platform you want to move.//左右移動(dòng)的平臺(tái)public class MovingPlatform : MonoBehaviour {  //Platform movement speed.平臺(tái)移動(dòng)速度 public float speed;  //This is the position where the platform will move.平臺(tái)移動(dòng)的位置 public Transform MovePosition;//創(chuàng)建一個(gè)空物體作為移動(dòng)的位置  private Vector3 StartPosition; private Vector3 EndPosition; private bool OnTheMove;  // Use this for initialization void Start () { //Store the start and the end position. Platform will move between these two points.儲(chǔ)存左右兩端點(diǎn)位置 StartPosition = this.transform.position; EndPosition = MovePosition.position; }  void FixedUpdate () {  float step = speed * Time.deltaTime;  if (OnTheMove == false) { this.transform.position = Vector3.MoveTowards (this.transform.position, EndPosition, step); }else{ this.transform.position = Vector3.MoveTowards (this.transform.position, StartPosition, step); }  //When the platform reaches end. Start to go into other direction. if (this.transform.position.x == EndPosition.x && this.transform.position.y == EndPosition.y && OnTheMove == false) { OnTheMove = true; }else if (this.transform.position.x == StartPosition.x && this.transform.position.y == StartPosition.y && OnTheMove == true) { OnTheMove = false; } }  }

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持武林網(wǎng)。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 沅陵县| 宁海县| 凤凰县| 新干县| 商都县| 屏东市| 华坪县| 蕉岭县| 东城区| 阜平县| 顺昌县| 南涧| 营口市| 临西县| 兴海县| 广州市| 射阳县| 加查县| 饶阳县| 阜阳市| 竹溪县| 安福县| 武隆县| 昌邑市| 新乡县| 南郑县| 井研县| 增城市| 雷州市| 临漳县| 阿合奇县| 洛浦县| 塘沽区| 济阳县| 德昌县| 长岭县| 同仁县| 九江县| 冷水江市| 吉木萨尔县| 建阳市|