Shrink Changes(not final)

main
thoopchuk26 4 years ago
parent a30e936cf0
commit 397e8ab91e

@ -25,17 +25,17 @@ public class GameManager : MonoBehaviour
public Sprite[] art;
public string[] artInfo;
public GameObject artImage;
public GameObject powerUps;
public GameObject gliderPowerupButton;
public GameObject boxPowerupButton;
public GameObject doubleJumpPowerupButton;
public GameObject shrinkPowerupButton;
public GameObject otherPowerupButton;
public GameObject powerupText;
public GameObject artImage;
public GameObject powerUps;
public GameObject gliderPowerupButton;
public GameObject boxPowerupButton;
public GameObject doubleJumpPowerupButton;
public GameObject shrinkPowerupButton;
public GameObject otherPowerupButton;
public GameObject powerupText;
private AudioSource sound;
@ -72,7 +72,7 @@ public class GameManager : MonoBehaviour
LoadLevel(sceneToLoad, new Vector3(0, 0, 0));
}*/
sound = GetComponent<AudioSource>();
GameManager.Instance.enablePowerup(3);
}
// Update is called once per frame
@ -88,6 +88,9 @@ public class GameManager : MonoBehaviour
{
sound.Play();
}
if (Input.GetKeyDown(KeyCode.Q)){
ShrinkButtonClicked();
}
}
public void LoadLevel(string levelName, Vector3 whereTo)
@ -146,10 +149,10 @@ public class GameManager : MonoBehaviour
{
startButton.SetActive(false);
title.SetActive(false);
panel.SetActive(false);
panel.SetActive(false);
healthbar.SetActive(true);
powerUps.SetActive(true);
disableAllPowerups();
powerUps.SetActive(true);
disableAllPowerups();
LoadLevel(sceneToLoad, new Vector3(0, 0, 0));
@ -159,48 +162,48 @@ public class GameManager : MonoBehaviour
return enemyHealthBar;
}
public void disablePowerup(int powerupID)
{
if (powerupID >= 0 && powerupID <= 4)
{
var powerup = powerUps.gameObject.transform.GetChild(powerupID);
powerup.gameObject.SetActive(false);
}
}
public void enablePowerup(int powerupID)
{
if (powerupID >= 0 && powerupID <= 4)
{
var powerup = powerUps.gameObject.transform.GetChild(powerupID);
powerup.gameObject.SetActive(true);
}
}
public void disableAllPowerups()
{
for(int i=0; i<=4; i++)
{
disablePowerup(i);
}
}
public void GliderButtonClicked()
{
Debug.Log("Is Gliding? " + player.GetComponent<Glider>().IsGliding);
player.GetComponent<Glider>().ToggleGliding();
}
public void ShrinkButtonClicked()
{
player.GetComponent<Shrink>().startShrinking();
Debug.Log("Start Shrink Logic");
}
public void DoubleJumpClicked()
{
player.GetComponent<movement>().maxJumps = 2;
public void disablePowerup(int powerupID)
{
if (powerupID >= 0 && powerupID <= 4)
{
var powerup = powerUps.gameObject.transform.GetChild(powerupID);
powerup.gameObject.SetActive(false);
}
}
public void enablePowerup(int powerupID)
{
if (powerupID >= 0 && powerupID <= 4)
{
var powerup = powerUps.gameObject.transform.GetChild(powerupID);
powerup.gameObject.SetActive(true);
}
}
public void disableAllPowerups()
{
for(int i=0; i<=4; i++)
{
disablePowerup(i);
}
}
public void GliderButtonClicked()
{
Debug.Log("Is Gliding? " + player.GetComponent<Glider>().IsGliding);
player.GetComponent<Glider>().ToggleGliding();
}
public void ShrinkButtonClicked()
{
Debug.Log("Start Shrink Logic");
player.GetComponent<Shrink>().startShrinking();
}
public void DoubleJumpClicked()
{
player.GetComponent<movement>().maxJumps = 2;
}
}

@ -24,7 +24,7 @@ public class Shrink : MonoBehaviour
rb2d = GetComponent<Rigidbody2D>();
col = GetComponent<CapsuleCollider2D>();
minRbSize = new Vector3(rb2d.transform.localScale.x * scaleShrink, rb2d.transform.localScale.y * scaleShrink, rb2d.transform.localScale.z);
minRbSize = new Vector3((rb2d.transform.localScale.x * scaleShrink) * 4, (rb2d.transform.localScale.y * scaleShrink) * 4, rb2d.transform.localScale.z);
minColSize = new Vector2(col.size.x * scaleShrink, col.size.y * scaleShrink);
defaultRbSize = rb2d.transform.localScale;
defaultColSize = col.size;
@ -34,13 +34,13 @@ public class Shrink : MonoBehaviour
// Update is called once per frame
void Update()
{
print(col.size + " " + rb2d.transform.localScale);
startShrinking();
//print(col.size + " " + rb2d.transform.localScale);
}
public void startShrinking()
{
RaycastHit2D ceiling = Physics2D.Raycast(rb2d.transform.position, transform.TransformDirection(Vector2.up), 2f);
Debug.Log("startshrinking()");
RaycastHit2D ceiling = Physics2D.Raycast(rb2d.transform.position, transform.TransformDirection(Vector2.up), 1f);
if (ceiling && isShrunk)
{
@ -49,6 +49,7 @@ public class Shrink : MonoBehaviour
}
else
{
Debug.Log("Able to Shrink");
canShrinkCheck();
}
StartCoroutine(shrinkLogic());
@ -56,35 +57,27 @@ public class Shrink : MonoBehaviour
IEnumerator shrinkLogic()
{
if (isShrunk && canShrink)
Debug.Log("Shrinking Logic");
if (isShrunk && canUnShrink)
{
print("unshrinking");
for (int i = 0; i < 3; i++) //unshrink
{
print("true");
for (int i = 0; i < 3; i++) //unshrink
{
if(((defaultColSize.x >= col.size.x) || (defaultRbSize.x >= rb2d.transform.localScale.x)))
{
rb2d.transform.localScale = new Vector3(rb2d.transform.localScale.x * scaleUnShrink, rb2d.transform.localScale.y * scaleUnShrink, rb2d.transform.localScale.z);
col.size = new Vector2(col.size.x * scaleUnShrink, col.size.y * scaleUnShrink);
yield return new WaitForSeconds(0.1f);
}
}
isShrunk = false;
rb2d.transform.localScale = new Vector3(rb2d.transform.localScale.x * scaleUnShrink, rb2d.transform.localScale.y * scaleUnShrink, rb2d.transform.localScale.z);
yield return new WaitForSeconds(0.05f);
}
else if (!isShrunk && canUnShrink)
isShrunk = false;
}
else if (!isShrunk)
{
print("shrinking");
for (int i = 0; i < 3; i++) //shrink
{
for (int i = 0; i < 3; i++) //shrink
{
if (((minColSize.x <= col.size.x) || (minRbSize.x <= rb2d.transform.localScale.x)))
{
rb2d.transform.localScale = new Vector3(rb2d.transform.localScale.x * scaleShrink, rb2d.transform.localScale.y * scaleShrink, rb2d.transform.localScale.z);
col.size = new Vector2(col.size.x * scaleShrink, col.size.y * scaleShrink);
yield return new WaitForSeconds(0.1f);
}
}
rb2d.transform.localScale = new Vector3(rb2d.transform.localScale.x * scaleShrink, rb2d.transform.localScale.y * scaleShrink, rb2d.transform.localScale.z);
yield return new WaitForSeconds(0.05f);
}
isShrunk = true;
}
}
public void cantShrinkCheck()

Loading…
Cancel
Save