找传奇、传世资源到传世资源站!

unity2d酷跑游戏(简易实现功能,慎重下载)

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

unity2d酷跑游戏(简易实现功能,慎重下载) C#语言基础-第1张using UnityEngine;using System.Collections;using System;public class PlayerStateController : MonoBehaviour{ public float delaytime; //按键延迟时间 public static int jumpcount = 0; //三级跳级数 public Vector2 jumpforce; //精灵跳跃力 public Vector2 slideforce; //精灵下滑的力 public Rigidbody2D playerBody = null; public BoxCollider2D playerCollider = null; //定义游戏人物的各种状态 public enum playerStates { run = 0, jump, slide, falling, landing, } //定义委托和事件 public delegate void playerStateHandler(PlayerStateController.playerStates newState); public static event playerStateHandler onStateChange; void Start() { playerBody = GetComponent<Rigidbody2D>(); playerCollider = GetComponent<BoxCollider2D>(); } void Update() { if (Input.GetKeyDown(KeyCode.S)&&!Input.GetKeyDown(KeyCode.L)) { playerCollider.size = new Vector2(0.6232159f, 0.4215094f); playerCollider.offset = new Vector2(0.1357977f, -0.2985263f); if (onStateChange != null) { onStateChange(PlayerStateController.playerStates.slide); } } if (Input.GetKey(KeyCode.S)) { playerBody.AddForce(slideforce); onStateChange(PlayerStateController.playerStates.slide); } if (Input.GetKeyUp(KeyCode.S)) { playerCollider.size = new Vector2(0.6232159f, 1.004287f); playerCollider.offset = new Vector2(0.1357977f, -0.007138014f); } if (Input.GetKeyDown(KeyCode.L) && !Input.GetKey(KeyCode.S)) { if (onStateChange != null) if (GetComponent<Animator>().GetBool("falling") == true || jumpcount < 3) { onStateChange(PlayerStateController.playerStates.jump); playerBody.AddForce(jumpforce); jumpcount ; } } } void LateUpdate() { if (Input.GetKeyUp(KeyCode.S)) { if (!GetComponent<Animator>().GetBool("falling")) { onStateChange(PlayerStateController.playerStates.run); } } if (Input.GetKeyUp(KeyCode.L)) { if (!GetComponent<Animator>().GetBool("falling")) { // onStateChange(PlayerStateController.playerStates.run); } } }}

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复