球球大作战 01 小球的移动和碰到金币,金币会消失。

版权申明:

  • 本文原创首发于以下网站:
  1. 博客园『优梦创客』的空间:https://www.cnblogs.com/raymondking123
  2. 优梦创客的官方博客:https://91make.top
  3. 优梦创客的游戏讲堂:https://91make.ke.qq.com
  4. 『优梦创客』的微信公众号:umaketop
  • 您可以自由转载,但必须加入完整的版权声明!

球球大作战小球的移动和碰到金币,金币会消失。

730245-20190824112432493-1005529133.png
吃到金币
730245-20190824112448461-1724290255.png

public class SphereMove : MonoBehaviour
{
    public float Spheremove = 20;
    public float Spherejump = 50;
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetKey(KeyCode.UpArrow))
        {
            GetComponent<Rigidbody>().AddForce(Spheremove, 0, 0);
        }
        if (Input.GetKey(KeyCode.DownArrow))
        {
            GetComponent<Rigidbody>().AddForce(-Spheremove, 0, 0); 
        }
        if (Input.GetKey(KeyCode.LeftArrow))
        {
            GetComponent<Rigidbody>().AddForce(0, 0, Spheremove);
        }
        if (Input.GetKey(KeyCode.RightArrow))
        {
            GetComponent<Rigidbody>().AddForce(0, 0, -Spheremove);
        }
        if (Input.GetKey(KeyCode.Space))
        {
            GetComponent<Rigidbody>().AddForce(0, Spherejump, 0);
        }
    }

    public void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.tag == ("Goodup"))
        {
          other.gameObject.SetActive(false); 
        }
      
    }
}
金币围绕Y轴转动金币围绕Y轴转动。

730245-20190824112518477-1016658216.gif

public class Pickupsctrl : MonoBehaviour
{

    public Vector3 rot;
    
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        rot = new Vector3(0, 20, 0);
        rot = rot* Time.deltaTime;
        transform.Rotate(rot);
    }
}
相机跟随小球移动相机跟随小球移动。

730245-20190824112535369-531461219.gif

public class Canearctrl : MonoBehaviour
{

    public Vector3 Offset;
    public Transform player;
    // Start is called before the first frame update
    void Start()
    {
        Offset = this.transform.position - player.position;
    }

    // Update is called once per frame
    void Update()
    {
        this.transform.position = player.position + Offset;
    }
}

转载于:https://www.cnblogs.com/raymondking123/p/11404018.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值