public TimeManager timeManager;
[SerializeField]
private float moveSpeed = 10.0f;
[SerializeField]
private float sideWaySpeed = 2f;
[SerializeField]
private float yVelocity;
//[SerializeField]
//public float jumpHeight = 10f;
Vector3 movement;
Rigidbody rb;
// Start is called before the first frame update
void Start()
{
timeManager = GetComponent<TimeManager>();
rb = GetComponent<Rigidbody>();
GameMaster.doublePickedUp = false;
GameMaster.magnetPickedUp = false;
}
// Update is called once per frame
void Update()
{
movement = Vector3.zero;
movement.x = Input.GetAxis("Horizontal") * sideWaySpeed;
if (Input.GetMouseButton(0))
{
if (Input.mousePosition.x > Screen.width / 2)
movement.x = sideWaySpeed;
else
movement.x = -sideWaySpeed;
}
movement.y = yVelocity;
movement.z = moveSpeed;
if (transform.position.y <= -1f)
{
this.enabled = false;
FindObjectOfType<GameMaster>().EndGame();
}
}
void FixedUpdate()
{
MovePlayer(movement);
}
void MovePlayer(Vector3 direction)
{
rb.AddForce(direction * moveSpeed);
}
/*private void OnCollisionEnter(Collision other)
{
if (other.collider.tag == "Obstacle")
{
this.enabled = false;
FindObjectOfType<GameMaster>().EndGame();
}
}*/
void OnTriggerEnter(Collider other)
{
/*if (other.CompareTag("Obstacle"))
{
this.enabled = false;
FindObjectOfType<GameMaster>().EndGame();
}*/
if (other.CompareTag("Coin") && !GameMaster.doublePickedUp)
{
Destroy(other.gameObject);
GameMaster.points += 1;
}
if (other.CompareTag("Coin") && GameMaster.doublePickedUp)
{
Destroy(other.gameObject);
GameMaster.points += 2;
}
if (other.CompareTag("RedCoin"))
{
Destroy(other.gameObject);
GameMaster.points += 5;
}
}
public void SetSpeed(float modifier)
{
moveSpeed = 10.0f * modifier;
}