-
Notifications
You must be signed in to change notification settings - Fork 1
/
MainMenuPlayerController.cs
43 lines (35 loc) · 1.07 KB
/
MainMenuPlayerController.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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MainMenuPlayerController : MonoBehaviour {
private Rigidbody2D rb;
private float jumpVelocity = 5f;
private float initHeight = 1.575f;
// Use this for initialization
void Awake () {
rb = GetComponent<Rigidbody2D>();
}
void OnCollisionEnter2D(Collision2D collision)
{
rb.velocity = new Vector2(rb.velocity.x, jumpVelocity);
}
public void SetInitHeight() {
rb.position = new Vector2(rb.position.x, initHeight);
}
public void ChangeCharacter(RuntimeAnimatorController anim) {
this.GetComponent<Animator>().runtimeAnimatorController = anim;
}
// Used for character selection
public void SetJump(bool on) {
if (on) {
jumpVelocity = 5f;
rb.position = new Vector2(rb.position.x, rb.position.y + 1.3f);
rb.gravityScale = 1.0f;
} else {
jumpVelocity = 0f;
rb.position = new Vector2(rb.position.x, initHeight);
rb.velocity = new Vector2(0, 0);
rb.gravityScale = 0f;
}
}
}