-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExtra.cs
More file actions
59 lines (55 loc) · 1.81 KB
/
Extra.cs
File metadata and controls
59 lines (55 loc) · 1.81 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
47
48
49
50
51
52
53
54
55
56
57
58
59
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Com.MyCompany.Pacman
{
public static class Extra
{
public static Vector2[] directions = new Vector2[]{
Vector2.up,
Vector2.right,
Vector2.down,
Vector2.left
};
public static Vector2 PerpendicularRight(Vector2 v)
{
for (int i = 0; i < directions.Length; i++)
{
Vector2 dir = directions[i];
if (dir == v)
{
int nextDir = i + 1;
if (nextDir == directions.Length)
{
nextDir = 0;
}
return directions[nextDir];
}
}
throw new KeyNotFoundException("Vector " + v + " is not a horizontal/vertical vector.");
}
public static Vector2 PerpendicularLeft(Vector2 v)
{
for (int i = 0; i < directions.Length; i++)
{
Vector2 dir = directions[i];
if (dir == v)
{
int nextDir = i - 1;
if (nextDir < 0)
{
nextDir = directions.Length - 1;
}
return directions[nextDir];
}
}
throw new KeyNotFoundException("Vector " + v + " is not a horizontal/vertical vector.");
}
}
}
/* =============================================================================
# Author: Divya Gandhi - https://github.com/divya16-bit
# Email: 16gandhi.hemani@gmail.com
# FileName: extra.cs
# Created On: 26/11/2020
============================================================================= */