unity2D 箭头动画(给猛虎桥章节做动画演示一)

铁血残明里面的好些故事情节精彩纷呈,可谓拍案惊奇,比如云际寺、猛虎桥等等,博主准备用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); 
    }


}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

刘欣的博客

你将成为第一个打赏博主的人!

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

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

打赏作者

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

抵扣说明:

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

余额充值