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

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

Loading…
Cancel
Save