Seascape/Assets/Scripts/PlayerScript.cs

155 lines
3.9 KiB
C#

using System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.SocialPlatforms.Impl;
using UnityEngine.UI;
public class PlayerScript : MonoBehaviour
{
[SerializeField] private float horizontalSpeed = 2;
[SerializeField] private float verticalSpeed = 4;
[SerializeField] private int MaxYCoordinate = 0;
[SerializeField] private int MinYCoordinate = -10;
[SerializeField] private int MaxXCoordinate = 10;
[SerializeField] private int MinXCoordinate = -10;
[SerializeField] private Text FischLabel;
public bool Fisch1Collected = false;
public bool Fisch2Collected = false;
public bool Fisch3Collected = false;
[SerializeField] private int sharkPoints = 2;
private int score1 = 2;
private int score2 = 5;
private int score3 = 10;
public GameObject WaveBullet;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
handleMovement();
MovementControlls();
}
private void MovementControlls()
{
Vector3 pos = transform.position;
if (Input.GetKey("w"))
{
pos.y += verticalSpeed * Time.deltaTime;
}
if (Input.GetKey("s"))
{
pos.y -= verticalSpeed * Time.deltaTime;
}
if (Input.GetKey("d"))
{
pos.x += horizontalSpeed * Time.deltaTime;
}
if (Input.GetKey("a"))
{
pos.x -= horizontalSpeed * Time.deltaTime;
}
if (Input.GetButtonDown("Cancel"))
{
SceneManager.LoadSceneAsync(2);
//if ()
//{
// if (Input.GetButtonDown("Cancel"))
// {
// SceneMan
// }
//}
}
transform.position = pos;
}
private void handleMovement()
{
float deltaX = Input.GetAxis("Horizontal") * horizontalSpeed; // Horizontal
float deltaY = Input.GetAxis("Vertical") * verticalSpeed; // Vertical
Vector3 movementDirection = new Vector3(deltaX, deltaY, 0);
// x-movement
transform.position += movementDirection * Time.deltaTime;
if (transform.position.x < MinXCoordinate)
{
transform.position = new Vector3(MinXCoordinate, transform.position.y, transform.position.z);
}
else if (transform.position.x > MaxXCoordinate)
{
transform.position = new Vector3(MaxXCoordinate, transform.position.y, transform.position.z);
}
// y-movement
if (transform.position.y < MinYCoordinate)
{
transform.position = new Vector3(transform.position.x, MinYCoordinate, transform.position.z);
}
else if (transform.position.y > MaxYCoordinate)
{
transform.position = new Vector3(transform.position.x, MaxYCoordinate, transform.position.z);
}
}
private void HaiScore()
{
if (Fisch1Collected == true)
{
sharkPoints += score1;
Fisch1Collected = false;
}
if (Fisch2Collected == true)
{
sharkPoints += score2;
Fisch2Collected = false;
}
if (Fisch3Collected == true)
{
sharkPoints += score3;
Fisch3Collected = false;
}
if (sharkPoints <= 0)
{
SceneManager.LoadSceneAsync(3);
}
}
private void OnTriggerEnter2D(Collider2D kaputt)
{
FishPoints Fischi = kaputt.GetComponent<FishPoints>();
if (Fischi != null)
{
Fischi.GetCollected();
Fisch1Collected = true;
HaiScore();
}
}
public int GetSharkPoints()
{
return sharkPoints;
}
}