Skip to content

Commit 60eba3d

Browse files
committed
Added RigidBody2d and SpriteRenderer Extensions
1 parent 3397c40 commit 60eba3d

File tree

4 files changed

+45
-2
lines changed

4 files changed

+45
-2
lines changed

Colver/Colver.csproj

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,13 @@
3939
<Reference Include="System.Data" />
4040
<Reference Include="System.Net.Http" />
4141
<Reference Include="System.Xml" />
42-
<Reference Include="UnityEngine.CoreModule">
43-
<HintPath>C:\Program Files\Unity\Hub\Editor\2019.2.11f1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.dll</HintPath>
42+
<Reference Include="UnityEngine">
43+
<HintPath>C:\Program Files\Unity\Hub\Editor\2019.2.11f1\Editor\Data\Managed\UnityEngine.dll</HintPath>
4444
</Reference>
4545
</ItemGroup>
4646
<ItemGroup>
47+
<Compile Include="Main\Rigidbody2DExtensions.cs" />
48+
<Compile Include="Main\SpriteRendererExtension.cs" />
4749
<Compile Include="Main\Transform2DExtensions.cs" />
4850
<Compile Include="Main\Vector2Extensions.cs" />
4951
<Compile Include="Properties\AssemblyInfo.cs" />
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using UnityEngine;
2+
3+
namespace Colver.Main
4+
{
5+
public static class Rigidbody2DExtension
6+
{
7+
/// <summary>
8+
/// Move the current RigidBody2D based on vertical and horizontal Forces
9+
/// </summary>
10+
/// <param name="rb">The body wich will be moved</param>
11+
/// <param name="verticalForce">Vertical force applied</param>
12+
/// <param name="horizontalForce">Horizontal force applied</param>
13+
/// <param name="speed">Force applied (affect horizontal and vertical forces)</param>
14+
public static void Move(this Rigidbody2D rb,float verticalForce,float horizontalForce,float speed = 1)
15+
{
16+
rb.AddForce(new Vector2(horizontalForce * speed,verticalForce * speed));
17+
}
18+
}
19+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using UnityEngine;
2+
3+
namespace Colver.Main
4+
{
5+
public static class SpriteRendererExtension
6+
{
7+
/// <summary>
8+
/// Sets a random color to a specific Sprite
9+
/// </summary>
10+
/// <param name="spr">Sprite wich will have the color changed</param>
11+
public static void RandomColor(this SpriteRenderer spr)
12+
{
13+
Color color = new Color(Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f));
14+
spr.material.color = color;
15+
}
16+
}
17+
}

Colver/Main/Transform2DExtensions.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ namespace Colver.Main
44
{
55
public static class Transform2DExtension
66
{
7+
/// <summary>
8+
/// Rotate the GameObject to the target coordinate
9+
/// </summary>
10+
/// <param name="trans">The object wich will be rotated</param>
11+
/// <param name="target">The place where the object will be rotated</param>
712
public static void LookToPosition(this Transform trans,Vector3 target)
813
{
914
trans.rotation = Quaternion.LookRotation(trans.position - target, Vector3.forward);

0 commit comments

Comments
 (0)