forked from StRobertCHSCS/ICS4U-PCP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmario.cs
More file actions
91 lines (64 loc) · 2.49 KB
/
mario.cs
File metadata and controls
91 lines (64 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
using UnityEngine;
using System.Collections;
public class mario : MonoBehaviour {
public float moveSpeed;
public float jumpHeight;
public Transform groundCheck;
public float groundCheckRadius;
public LayerMask whatIsGround;
private bool grounded;
private bool doubleJumped;
private Animator anim;
public Transform firePointRight, firePointLeft;
public GameObject fireBall;
// Use this for initialization
void Start () {
anim = GetComponent<Animator> ();
}
void FixedUpdate() {
grounded = Physics2D.OverlapCircle (groundCheck.position, groundCheckRadius, whatIsGround);
}
// Update is called once per frame
void Update () {
if (grounded)
doubleJumped = false;
if (Input.GetKeyDown (KeyCode.W) && grounded)
{
//GetComponent<Rigidbody2D>().velocity = new Vector2 (GetComponent<Rigidbody2D>().velocity.x, jumpHeight);
Jump();
}
if (Input.GetKeyDown (KeyCode.W) && !doubleJumped && !grounded)
{
//GetComponent<Rigidbody2D>().velocity = new Vector2 (GetComponent<Rigidbody2D>().velocity.x, jumpHeight);
Jump();
doubleJumped = true;
}
if (Input.GetKey (KeyCode.D))
{
GetComponent<Rigidbody2D> ().velocity = new Vector2 (moveSpeed, GetComponent<Rigidbody2D> ().velocity.y);
//anim.SetFloat("Speed Right", Mathf.Abs(GetComponent<Rigidbody2D> ().velocity.x));
}
if (Input.GetKey (KeyCode.A))
{
GetComponent<Rigidbody2D> ().velocity = new Vector2 (-moveSpeed, GetComponent<Rigidbody2D> ().velocity.y);
//anim.SetFloat("Speed Left", Mathf.Abs(GetComponent<Rigidbody2D> ().velocity.x));
}
anim.SetFloat("Speed", (GetComponent<Rigidbody2D> ().velocity.x));
//anim.SetFloat("Speed", 0);
// if (GetComponent<Rigidbody2D>().velocity.x > 0)
// transform.localScale = new Vector3(1f, 1f, 1f);
// else if (GetComponent<Rigidbody2D>().velocity.x < 0)
// transform.localScale = new Vector3(-1f, 1f, 1f);
if (Input.GetKeyDown(KeyCode.F))
{
if (GetComponent<Rigidbody2D>().velocity.x > 0)
Instantiate(fireBall, firePointRight.position, firePointRight.rotation);
else if (GetComponent<Rigidbody2D>().velocity.x < 0)
Instantiate(fireBall, firePointLeft.position, firePointLeft.rotation);
}
}
public void Jump()
{
GetComponent<Rigidbody2D>().velocity = new Vector2 (GetComponent<Rigidbody2D>().velocity.x, jumpHeight);
}
}