mirror of
https://github.com/Xevion/Galagan.git
synced 2026-01-31 08:24:24 -06:00
minor cleanup Player.cs
This commit is contained in:
@@ -8,8 +8,8 @@ public class Player : MonoBehaviour
|
|||||||
private PolygonCollider2D _polygonCollider;
|
private PolygonCollider2D _polygonCollider;
|
||||||
private Rigidbody2D _rigidbody;
|
private Rigidbody2D _rigidbody;
|
||||||
|
|
||||||
private float minX;
|
private float _minX;
|
||||||
private float maxX;
|
private float _maxX;
|
||||||
|
|
||||||
[Range(0.01f, 1.2f)] public float shipWidth = 1.3f;
|
[Range(0.01f, 1.2f)] public float shipWidth = 1.3f;
|
||||||
[Range(0.01f, 1.2f)] public float shipHeight = 0.8f;
|
[Range(0.01f, 1.2f)] public float shipHeight = 0.8f;
|
||||||
@@ -27,23 +27,18 @@ public class Player : MonoBehaviour
|
|||||||
_lineRenderer.useWorldSpace = false;
|
_lineRenderer.useWorldSpace = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Start()
|
private void Start()
|
||||||
{
|
{
|
||||||
for (var i = 0; i < SceneManager.sceneCount; i++)
|
|
||||||
{
|
|
||||||
Debug.Log(SceneManager.GetSceneAt(i).name);
|
|
||||||
}
|
|
||||||
GenerateShape();
|
GenerateShape();
|
||||||
|
|
||||||
var cam = Camera.main;
|
var cam = Camera.main!;
|
||||||
var inset = 0.05f;
|
const float inset = 0.05f;
|
||||||
minX = cam.ScreenToWorldPoint(new Vector3(cam.pixelWidth * inset, 0, cam.nearClipPlane)).x;
|
_minX = cam.ScreenToWorldPoint(new Vector3(cam.pixelWidth * inset, 0, cam.nearClipPlane)).x;
|
||||||
maxX = cam.ScreenToWorldPoint(new Vector3(cam.pixelWidth * (1f - inset), 0, cam.nearClipPlane)).x;
|
_maxX = cam.ScreenToWorldPoint(new Vector3(cam.pixelWidth * (1f - inset), 0, cam.nearClipPlane)).x;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GenerateShape()
|
private void GenerateShape()
|
||||||
{
|
{
|
||||||
|
|
||||||
var points = new[]
|
var points = new[]
|
||||||
{
|
{
|
||||||
new Vector2(0, shipHeight),
|
new Vector2(0, shipHeight),
|
||||||
@@ -66,11 +61,11 @@ public class Player : MonoBehaviour
|
|||||||
if (collision.gameObject.CompareTag("Asteroid"))
|
if (collision.gameObject.CompareTag("Asteroid"))
|
||||||
{
|
{
|
||||||
// Load main menu
|
// Load main menu
|
||||||
var index = UnityEngine.SceneManagement.SceneManager.GetSceneByName("MenuScene").buildIndex;
|
var index = SceneManager.GetSceneByName("MenuScene").buildIndex;
|
||||||
// Only error in proper builds
|
// Only error in proper builds
|
||||||
|
|
||||||
// if (index == -1 &&
|
if (index != -1)
|
||||||
// UnityEngine.SceneManagement.SceneManager.LoadScene(index);
|
SceneManager.LoadScene(index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,11 +74,10 @@ public class Player : MonoBehaviour
|
|||||||
_rigidbody.velocity = Vector2.zero;
|
_rigidbody.velocity = Vector2.zero;
|
||||||
transform.position += new Vector3(Input.GetAxis("Horizontal") * 0.4f, 0, 0);
|
transform.position += new Vector3(Input.GetAxis("Horizontal") * 0.4f, 0, 0);
|
||||||
|
|
||||||
// Prevent moving off screen
|
// Prevent moving off-screen
|
||||||
if (transform.position.x > maxX)
|
if (transform.position.x > _maxX)
|
||||||
transform.position = new Vector3(maxX, transform.position.y, transform.position.z);
|
transform.position = new Vector3(_maxX, transform.position.y, transform.position.z);
|
||||||
else if (transform.position.x < minX)
|
else if (transform.position.x < _minX)
|
||||||
transform.position = new Vector3(minX, transform.position.y, transform.position.z);
|
transform.position = new Vector3(_minX, transform.position.y, transform.position.z);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user