-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFoodChooserRay.cs
More file actions
33 lines (29 loc) · 882 Bytes
/
Copy pathFoodChooserRay.cs
File metadata and controls
33 lines (29 loc) · 882 Bytes
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
using Godot;
using System;
public class FoodChooserRay : RayCast
{
private GameEvents _gameEvents;
private bool _isMousingOver = false;
public override void _Ready()
{
// todo: this breaks if the fs is changed, should I just attach a reference of the script on the editor(?)
_gameEvents = GetNode<GameEvents>("/root/GameEvents");
}
public override void _Input(InputEvent e)
{
Area collidedArea = GetCollider() as Area;
if (collidedArea is Food food)
{
if (!_isMousingOver)
{
_isMousingOver = true;
_gameEvents.EmitSignal(nameof(GameEvents.foodMousedOver), food);
}
}
else if (_isMousingOver)
{
_isMousingOver = false;
_gameEvents.EmitSignal(nameof(GameEvents.foodMousedOut));
}
}
}