-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbunnyMovement.cs
85 lines (72 loc) · 2.19 KB
/
bunnyMovement.cs
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class bunnyMovement : MonoBehaviour {
[SerializeField]private Transform Cylinder;
public float jumpforce = 2f;
public float Speed;
private bool faceingRight = false;
private Rigidbody2D rb;
private bool Grounded;
public Transform groundCheck;
public float checkRadius;
public LayerMask WIGround;
public float waitTime;
private float nextTime = 0;
public float FSpeed;
// Use this for initialization
void Start () {
rb = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update ()
{
Grounded = Physics2D.OverlapCircle (groundCheck.position, checkRadius, WIGround);
nextTime += Time.deltaTime;
if (Cylinder.transform.position.x - transform.position.x > 0 && Cylinder.transform.position.x - transform.position.x < 10) {
if (Grounded && nextTime >= waitTime) {
Debug.Log ("Yeeh");
rb.AddForce (new Vector2 (Speed, jumpforce), ForceMode2D.Impulse);
Grounded = false;
nextTime = 0;
}
}
if (Cylinder.transform.position.x - transform.position.x < 0 && Cylinder.transform.position.x - transform.position.x > -10) {
if (Grounded && nextTime >= waitTime) {
Debug.Log ("Yee");
rb.AddForce (new Vector2 (FSpeed, jumpforce), ForceMode2D.Impulse);
Grounded = false;
nextTime = 0;
}
}
if (faceingRight == false && Cylinder.transform.position.x - transform.position.x > 0) {
Flip ();
} else if (faceingRight == true && Cylinder.transform.position.x - transform.position.x < 0) {
Flip ();
}
}
void Flip(){
Vector3 Scaler = transform.localScale;
Vector3 position = transform.position;
Scaler.x *= -1;
if (faceingRight == true) {
position.x -= -3f;
}
if (faceingRight == false) {
position.x -= 3f;
}
transform.position = position;
transform.localScale = Scaler;
faceingRight = !faceingRight;
}
IEnumerator wait(){
yield return new WaitForSeconds (waitTime);
rb.velocity = Vector2.zero;
}
void OnTriggerEnter2D(Collider2D other){
if (other.tag == "goodBullet") {
Destroy (other);
Destroy (gameObject);
}
}
}