zoukankan      html  css  js  c++  java
  • 球球大作战 01 小球的移动和碰到金币,金币会消失。

    版权申明:

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

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


    吃到金币

    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轴转动。

    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);
        }
    }
    

    相机跟随小球移动相机跟随小球移动。

    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;
        }
    }
    
  • 相关阅读:
    Teamviewer12完美破解版去除时间限制完美使用
    winFrom程序更新自动安装
    sql 根据指定字符截取前面几个字符
    下拉框带搜索
    easyui 展开缩起
    p1001 谁拿了最多的奖学金
    p1217 乒乓球
    p1911 珠心算问题
    p1848 记数问题
    入坑archlinux
  • 原文地址:https://www.cnblogs.com/raymondking123/p/11404018.html
Copyright © 2011-2022 走看看