mirror of
https://github.com/PashaBibko/The-Mobius-Line.git
synced 2026-04-03 17:39:03 +00:00
WERE FLYING IN DA AIR
This commit is contained in:
32
Assets/Scripts/GravityController.cs
Normal file
32
Assets/Scripts/GravityController.cs
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
public class GravityController
|
||||||
|
{
|
||||||
|
// The only instance of the class
|
||||||
|
static GravityController s_Instance = null;
|
||||||
|
|
||||||
|
// Constant gravity scale
|
||||||
|
const float m_GravityScale = 20.0f;
|
||||||
|
|
||||||
|
// Private constructor to stop accidental creation
|
||||||
|
private GravityController()
|
||||||
|
{ }
|
||||||
|
|
||||||
|
public static GravityController Instance()
|
||||||
|
{
|
||||||
|
// Creates an instance if there is not already one
|
||||||
|
if (s_Instance == null)
|
||||||
|
{
|
||||||
|
s_Instance = new GravityController();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Returns the instance
|
||||||
|
return s_Instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetScale(float scale)
|
||||||
|
{
|
||||||
|
// Sets the gravity
|
||||||
|
Physics.gravity = new Vector3(0, m_GravityScale * scale, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Assets/Scripts/GravityController.cs.meta
Normal file
11
Assets/Scripts/GravityController.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 56c7a2685fd932c4aa322d5b48fbd2aa
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -79,6 +79,10 @@ public partial class PlayerMovement : MonoBehaviour
|
|||||||
if (Mathf.Abs(v.z) < 0.1f) { v.z = 0.0f; }
|
if (Mathf.Abs(v.z) < 0.1f) { v.z = 0.0f; }
|
||||||
m_Body.velocity = v;
|
m_Body.velocity = v;
|
||||||
|
|
||||||
|
// Doubles gravity if falling to feel less floaty
|
||||||
|
if (v.y < 0.0f) { GravityController.Instance().SetScale(2.0f); }
|
||||||
|
else { GravityController.Instance().SetScale(1.0f); }
|
||||||
|
|
||||||
// Clears all stored collisions
|
// Clears all stored collisions
|
||||||
m_WallCollisions.Clear();
|
m_WallCollisions.Clear();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user