0% found this document useful (0 votes)
4 views1 page

Player Behaviour

The document describes a PlayerBehaviour script that controls a player object in a game. The script handles the player's size, intangibility timer, and collision with powerups that change the player's size.

Uploaded by

jooj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views1 page

Player Behaviour

The document describes a PlayerBehaviour script that controls a player object in a game. The script handles the player's size, intangibility timer, and collision with powerups that change the player's size.

Uploaded by

jooj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

using System.

Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerBehaviour : MonoBehaviour


{
public int size = 0;
public bool intangible = false;
float timer;
private void Update()
{
if (intangible == true)
{
timer += Time.deltaTime;
if (timer >= 1)
{
intangible = false;
timer = 0f;
}
}
}

private void OnCollisionEnter2D(Collision2D collision)


{
if (collision.gameObject.CompareTag("PowerUp"))
{
Destroy(collision.gameObject);
size = 1;
ChangeSize();
}
}

public void ChangeSize()


{
switch (size)
{
case 0:
transform.localScale = new Vector3(1, 0.5f, 1);
break;
case 1:
transform.localScale = new Vector3(1, 1, 1);
break;
case 2:
//flor
break;
}
}
}

You might also like