zoukankan      html  css  js  c++  java
  • 小球跳跃游戏

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.UI;
    
    public class SphereControll : MonoBehaviour {
        bool b = false;
        public float sphereSpeed=10;//以监视面板赋值为准,如果外界改值调用外界的值
        public float sphereJump=20;
        public Image image;
        // Use this for initialization
        void Start () {
            image = image.GetComponent<Image>();
            image.gameObject.SetActive(false);
            //GetComponent<BoxCollider>().enabled = false;//控制组件或者挂载的脚本的激活失活
        }
        
        // Update is called once per frame
        void Update ()
        {
            if (Input.GetKey(KeyCode.A)|| Input.GetKey(KeyCode.D))
            {
                transform.rotation = Quaternion.identity;//相当于无旋转
            }
            if (b)
            {
                if (Input.GetKey(KeyCode.A))
                {
                    GetComponent<Rigidbody>().AddForce(-transform.right* sphereSpeed * Time.deltaTime);//移动
                }
                if (Input.GetKey(KeyCode.D))
                {
                    GetComponent<Rigidbody>().AddForce(transform.right* sphereSpeed * Time.deltaTime);
                }
                if (Input.GetKey(KeyCode.Space))
                {
                    GetComponent<Rigidbody>().AddForce(transform.up* sphereJump*Time.deltaTime);
                }
            }
           
            
        }
        private void OnCollisionEnter(Collision collision)
        {
            if (collision.gameObject.tag.Equals( "Player"))
            {
                b = true;
               // transform.parent = collision.gameObject.transform; 
            }
            if (collision.gameObject.name=="Cube")
            {
                image.gameObject.SetActive(true);
                image.CrossFadeAlpha(0,3,true);//ui界面淡入淡出
                GetComponent<Rigidbody>().Sleep();
                transform.position = new Vector3(-1,-1,0);
    
                GetComponent<Rigidbody>().WakeUp();
                Invoke("ImageFalse",3);//延迟调用该方法
            }
        }
        public void ImageFalse() {
            image.color = Color.red;
            image.gameObject.SetActive(false);
        }
        private void OnCollisionStay(Collision collision)
        {
            if (collision.gameObject.tag.Equals("Player"))
            {
                b = true;
            }
        }
        private void OnCollisionExit(Collision collision)
        {
            if (collision.gameObject.tag.Equals("Player"))
            {
                b = false;
                transform.parent = null;
            }
        }
    
    }
    莫说我穷的叮当响,大袖揽清风。 莫讥我困时无处眠,天地做床被。 莫笑我渴时无美酒,江湖来做壶。
  • 相关阅读:
    禾匠 运行h5
    禾匠 前端用户中心显示隐藏菜单
    禾匠 创建新插件
    芸众如何查看前端版本
    查看电脑内存条个数 和 内存是ddr几代
    yii框架中的andFilterWhere 和 andWhere的区别
    mysql 5.7之前版本截取json字符串的值
    FTP上传文件总是上传一半就断掉
    Java中如何保证线程安全性
    Java8内存结构解读
  • 原文地址:https://www.cnblogs.com/huang--wei/p/9609248.html
Copyright © 2011-2022 走看看