-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPlayerScript.cs
More file actions
46 lines (39 loc) · 1.1 KB
/
PlayerScript.cs
File metadata and controls
46 lines (39 loc) · 1.1 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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerScript : MonoBehaviour
{
public Rigidbody2D rb2d;
public float moveSpeed;
Vector2 movement;
public Animator anim;
public bool hasCat;
public bool hasSeed;
// Start is called before the first frame update
void Start()
{
rb2d = GetComponent<Rigidbody2D>();
anim = GetComponent<Animator>();
}
// Update is called once per frame
void Update()
{
movement.x = Input.GetAxisRaw("Horizontal");
movement.y = Input.GetAxisRaw("Vertical");
//Animations
anim.SetFloat("Horizontal", movement.x);
anim.SetFloat("Vertical", movement.y);
anim.SetFloat("Speed", movement.sqrMagnitude);
//G4C Game
}
private void FixedUpdate()
{
rb2d.MovePosition(rb2d.position + movement * moveSpeed * Time.fixedDeltaTime);
}
private void OnTriggerExit2D(Collider2D collision)
{
if (collision.gameObject.tag == "Soil")
{
}
}
}