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;
            }
        }
    
    }
    莫说我穷的叮当响,大袖揽清风。 莫讥我困时无处眠,天地做床被。 莫笑我渴时无美酒,江湖来做壶。
  • 相关阅读:
    剖析虚幻渲染体系(12) 移动端专题Part 1(UE移动端渲染分析)
    剖析虚幻渲染体系(13) RHI补充篇:现代图形API之奥义与指南
    剖析虚幻渲染体系(12) 移动端专题Part 3(渲染优化)
    浏览器无环境调试
    RPC调用获取参数值
    vscode插件
    前端异常收集和处理
    互联网名词集锦
    今日思考20211104
    备忘项目进展萃取
  • 原文地址:https://www.cnblogs.com/huang--wei/p/9609248.html
Copyright © 2011-2022 走看看