-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFood.cs
46 lines (40 loc) · 1.19 KB
/
Food.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
using Godot;
using System;
public class Food : Area
{
[Export]
public string FoodName;
private GameEvents _gameEvents;
private SpotLight _spotLight;
private float _spinSpeed = 180;
[Export]
private NodePath _foodMeshPath;
private Spatial _foodMesh;
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");
_spotLight = GetNode<SpotLight>("SpotLight");
_foodMesh = GetNode<Spatial>(_foodMeshPath);
_gameEvents.Connect(nameof(GameEvents.foodMousedOver), this, nameof(_OnMouseEntered));
_gameEvents.Connect(nameof(GameEvents.foodMousedOut), this, nameof(_OnMouseOut));
}
public override void _Process(float delta)
{
if (_spotLight.Visible)
{
_foodMesh.RotationDegrees += new Vector3(0, _spinSpeed, 0) * delta;
}
}
private void _OnMouseEntered(Food food)
{
if (food == this)
{
_spotLight.Visible = true;
}
}
private void _OnMouseOut()
{
_spotLight.Visible = false;
}
}