铁血残明里面的好些故事情节精彩纷呈,可谓拍案惊奇,比如云际寺、猛虎桥等等,博主准备用unity对猛虎桥章节做一个动态的推演,也算是想早早把故事搬上荧屏的慰藉吧。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NewBehaviourScript : MonoBehaviour
{
public MyMapObject mmo = new MyMapObject();
void Start()
{
mmo.init_at(transform);
}
void Update()
{
mmo.move_at(transform);
}
}
public class MyMapObject
{
public List<Vector2> theWayPoints = new List<Vector2>();
public int point_index = 0;
public float zoom_speed = 0.2f;
public int move_speed = 50;
public void init_at(Transform transform)
{
Vector2 pos = transform.position;
pos.x = 350;
pos.y = 170;
theWayPoints.Add(pos);
pos.x = 600;
pos.y = 223;
theWayPoints.Add(pos);
pos.x = 800;
pos.y = 500;
theWayPoints.Add(pos);
pos.x = 800;
pos.y = 500;
theWayPoints.Add(pos);
}
public void move_at(Transform transform) //向目标点移动
{
transform.position = Vector2.MoveTowards(transform.position, theWayPoints[point_index], move_speed * Time.deltaTime);
check_point(transform);
}
public void check_point(Transform transform)
{
if (transform.position.Equals(theWayPoints[point_index])) //如果到了下一个点
{
point_index++;
look_at(transform);
redo_at(transform);
}
else
{
scale_at(transform);
}
}
public void look_at(Transform transform)//朝向目标点
{
Vector2 v = (theWayPoints[point_index] - (Vector2)transform.position).normalized;
transform.right = v; //右边为正前方
}
public void scale_at(Transform transform)//向右放大
{
transform.localScale += Vector3.right * zoom_speed * Time.deltaTime;
}
public void redo_at(Transform transform) //长宽回到原样
{
transform.localScale = Vector2.one;
((RectTransform)transform).sizeDelta = new Vector2(100, 100);
}
}