01_iTween_第一天--小球抛物线

实现小球的抛物线,结果如下:

【实现策略】

1.小球的初始位置为面板中心Vector.zero

2.射线检测出与面板的碰撞点确定小球的抛物落点

3.小球需要在XZ、Y上分别移动

4.  

    4.1小球在Y轴上产生抛物线效果  

    4.2小球在XY面直线移动;a+b融合=小球抛物运动

5.iTween的移动方法没有多动画融合需要设定两个不同的命令堆来使物体运动如MoveBy  MoveTo  --全部命令堆方法链接中英对照离线文档

    5.1.小球模型结构:父物件为空利用命令堆MoveTo,子物件子物件为预置Sphere球体利用命令堆MoveBy

    5.2.MoveBy  MoveTo与其他命令方法作用只是将设定参数分别加入到不同的命令堆中,再由iTween中的委托方法分别调用,区别方法是利用iTween中的Method参数不同MoveBy  是 "by"值,Moveto是"to"值,FadeTo是"color"值,后续不在阐述可自行参看iTween源码

【场景布置】

地面

落点位置显示图标

游戏控制者初始化

小球结构

【源代码】

public class GameController : MonoBehaviour {

    public Transform target;    //小球落点图标
    public GameObject bomb;     //小球模型

    void Update()
    {
        RaycastHit hit = new RaycastHit();
        Ray cameraRay = Camera.main.ScreenPointToRay(Input.mousePosition);
        if (Physics.Raycast(cameraRay.origin, cameraRay.direction, out hit, 100))
        {
            target.position = new Vector3(hit.point.x, 0.1f,hit.point.z);
        }

        if (Input.GetMouseButtonDown(0))
        {
            GameObject newBomb = Instantiate(bomb);
            Bomb newBombScript = newBomb.GetComponent<Bomb>();
            newBombScript.targetPosition = target.position;
            newBombScript.StartDo();
        }
    }
}
public class Bomb : MonoBehaviour {

    public GameObject core;
    float lobHeight = 4;
    float lobTime = 0.7f;
    public Vector3 targetPosition;

    public void StartDo() {
        iTween.MoveBy(core, iTween.Hash("y", lobHeight, "time", lobTime / 2, "easeType", iTween.EaseType.easeOutQuad));
        iTween.MoveBy(core, iTween.Hash("y", -lobHeight, "time", lobTime / 2, "delay", lobTime / 2, "easeType", iTween.EaseType.easeInCubic));
        iTween.MoveTo(gameObject, iTween.Hash("position", targetPosition, "time", lobTime, "easeType", iTween.EaseType.linear));
        iTween.FadeTo(gameObject, iTween.Hash("delay", 3, "time", .5, "alpha", 0, "onComplete", "CleanUp"));
    }

    void CleanUp()
    {
        Destroy(this.gameObject);
    }
}
        主要方法解释:
    将提供的amount坐标设定到target对象的移动位置移动花费time量的时间;支持哈希值设定全部命令。
    MoveBy(GameObject target, Vector3 amount, float time)
    MoveBy(GameObject target, Hashtable args)
 
    将游戏对象target的位置随时间time更改为提供的目的地position;支持哈希值设定全部命令。
    MoveTo(GameObject target, Vector3 position, float time)
    MoveTo(GameObject target, Hashtable args)
      
    随着时间的推移,改变游戏对象的 alpha 值。 如果附加 Light,GUIText 或 GUIText 组件,它将成为动画的目标;支持哈希值设定全部命令。
    FadeTo(GameObject target, float alpha, float time)
    FadeTo(GameObject target, Hashtable args)

【项目文件】

https://download.csdn.net/download/f980511/10564450

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值