-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCollisionManager.cs
More file actions
40 lines (35 loc) · 1.33 KB
/
CollisionManager.cs
File metadata and controls
40 lines (35 loc) · 1.33 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
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
namespace RTS_Engine;
public class CollisionManager
{
private List<GameObject> _gameObjects;
public CollisionManager(List<GameObject> gameObjects)
{
_gameObjects = gameObjects;
}
public void CheckColissions()
{
foreach (GameObject gameObject in _gameObjects)
{
if (!gameObject.Active) continue;
foreach (GameObject otherGameObject in _gameObjects)
{
if (!otherGameObject.Active) continue;
if (gameObject == otherGameObject) continue;
if (gameObject.GetComponent<Collider>() == null || otherGameObject.GetComponent<Collider>() == null) continue;
if (gameObject.GetComponent<Collider>().sphere.Intersects(otherGameObject.GetComponent<Collider>().sphere))
{
gameObject.GetComponent<Collider>().isColliding = true;
otherGameObject.GetComponent<Collider>().isColliding = true;
}
else
{
gameObject.GetComponent<Collider>().isColliding = false;
otherGameObject.GetComponent<Collider>().isColliding = false;
}
}
}
}
}