-
Thông tin
-
Quiz
Bài tập thực hành: Play control môn Cơ sở lập trình cuối học kì 2 (p1) | Đại học Văn Lang
Bài tập thực hành: Play control môn Cơ sở lập trình cuối học kì 2 (p1) | Đại học Văn Lang giúp sinh viên tham khảo, ôn luyện và phục vụ nhu cầu học tập của mình cụ thể là có định hướng, ôn tập, nắm vững kiến thức môn học và làm bài tốt trong những bài kiểm tra, bài tiểu luận, bài tập kết thúc học phần, từ đó học tập tốt và có kết quả cao cũng như có thể vận dụng tốt những kiến thức mình đã học
Cơ sở lập trình (CSLT) 10 tài liệu
Đại học Văn Lang 742 tài liệu
Bài tập thực hành: Play control môn Cơ sở lập trình cuối học kì 2 (p1) | Đại học Văn Lang
Bài tập thực hành: Play control môn Cơ sở lập trình cuối học kì 2 (p1) | Đại học Văn Lang giúp sinh viên tham khảo, ôn luyện và phục vụ nhu cầu học tập của mình cụ thể là có định hướng, ôn tập, nắm vững kiến thức môn học và làm bài tốt trong những bài kiểm tra, bài tiểu luận, bài tập kết thúc học phần, từ đó học tập tốt và có kết quả cao cũng như có thể vận dụng tốt những kiến thức mình đã học
Môn: Cơ sở lập trình (CSLT) 10 tài liệu
Trường: Đại học Văn Lang 742 tài liệu
Thông tin:
Tác giả:


Tài liệu khác của Đại học Văn Lang
Preview text:
using System.Collections;
using System.Collections.Generic; using UnityEngine;
public class PlayerControl : MonoBehaviour {
// Start is called before the first frame update public float moveForce = 20f;
public float jumpForce = 300f;
public float maxVelocity = 4f; private bool isGrounded; public int _score = 0; private Rigidbody2D myBody; private Animator animator; Start() void { } Awake() void { myBody = GetComponent(); animator = GetComponent(); } Update() void {
// if (Static.s_score >= 10) {
// Application.LoadLevel("Scene2"); } }
// Update is called once per frame FixedUpdate() void { PlayerWalk(); } PlayerWalk() void { float forceX = 0f; float forceY = 0f;
float vel = Mathf.Abs(myBody.velocity.x);
float h = Input.GetAxisRaw("Horizontal"); if (h > 0) { if (vel < maxVelocity) { forceX = moveForce; }
Vector3 scale = transform.localScale; scale.x = 2f; transform.localScale = scale;
animator.SetInteger("state", 1); } else if (h < 0) { if (vel < maxVelocity) { forceX = -moveForce; }
Vector3 scale = transform.localScale; scale.x = -2f; transform.localScale = scale;
animator.SetInteger("state", 1); } else if (h == 0) {
animator.SetInteger("state", 0); }
if (Input.GetKey(KeyCode.UpArrow)) { if (isGrounded) { isGrounded = false; forceY = jumpForce;
animator.SetInteger("state", 2); } } if (Input.GetKey(KeyCode.F)) {
animator.SetInteger("state", 4); } if (Input.GetKey(KeyCode.G)) {
animator.SetInteger("state", 3); } if (Input.GetKey(KeyCode.H)) {
animator.SetInteger("state", 5); }
myBody.AddForce(new Vector2(forceX, forceY)); } OnCollisionEnter2D(Collision2 void D target) { if (target.gameObject.tag == ) "Ground" { isGrounded = true; } } }