Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class GrowGround : MonoBehaviour
- {
- Vector2 PlayerPos;
- Vector2 GroundPos;
- float Dis1, Dis2, Dis3, Dis4;
- float UpSignAlpha = 0, DownSignAlpha = 0, RightSighAlpha = 0, LeftSignAlpha = 0;
- bool isUpSpawn = false, isDownSpawn = false, isRightSpawn = false, isLeftSpawn = false;
- bool isSetUp = false, isSetDown = false, isSetRight = false, isSetLeft = false;
- bool isUpFade = false, isDownFade = false, isRightFade = false, isLeftFade = false;
- public GameObject[] SignSelect;
- public GameObject GroundClone;
- public GameObject GroundPrefabe;
- void Start ()
- {
- GroundPos = new Vector2 (this.transform.position.x, this.transform.position.y);
- for (int i = 0; i < SignSelect.Length; i++) {
- SignSelect [i].SetActive (false);
- }
- }
- void Update ()
- {
- GroundSpawn ();
- SignFade ();
- }
- void GroundSpawn ()
- {
- PlayerPos = new Vector2 (GameObject.Find ("Player").transform.position.x, GameObject.Find ("Player").transform.position.y);
- Dis1 = Vector2.Distance (new Vector2 (GroundPos.x, GroundPos.y + 1f), PlayerPos);
- Dis2 = Vector2.Distance (new Vector2 (GroundPos.x, GroundPos.y - 1f), PlayerPos);
- Dis3 = Vector2.Distance (new Vector2 (GroundPos.x + 1f, GroundPos.y), PlayerPos);
- Dis4 = Vector2.Distance (new Vector2 (GroundPos.x - 1f, GroundPos.y), PlayerPos);
- if (isUpSpawn == true) {
- RaycastHit2D hit = Physics2D.Raycast (new Vector2 (GroundPos.x, GroundPos.y + 0.55f), new Vector2 (0, 0.5f), 0.1f);
- if (Dis1 > 1f) {
- SignSelect [0].SetActive (false);
- if (hit.collider != null) {
- if (hit.collider.tag == "Ground") {
- isUpSpawn = false;
- }
- } else {
- isUpSpawn = false;
- GroundClone = Instantiate (GroundPrefabe, this.transform.position + new Vector3 (0, 1f, 0), Quaternion.identity);
- }
- }
- }
- if (isDownSpawn == true) {
- RaycastHit2D hit = Physics2D.Raycast (new Vector2 (GroundPos.x, GroundPos.y - 0.55f), new Vector2 (0, -0.5f), 0.1f);
- if (Dis2 > 1f) {
- SignSelect [1].SetActive (false);
- if (hit.collider != null) {
- if (hit.collider.tag == "Ground") {
- isDownSpawn = false;
- }
- } else {
- isDownSpawn = false;
- GroundClone = Instantiate (GroundPrefabe, this.transform.position + new Vector3 (0, -1f, 0), Quaternion.identity);
- }
- }
- }
- if (isRightSpawn == true) {
- RaycastHit2D hit = Physics2D.Raycast (new Vector2 (GroundPos.x + 0.55f, GroundPos.y), new Vector2 (0.5f, 0), 0.1f);
- if (Dis3 > 1.1f) {
- SignSelect [2].SetActive (false);
- if (hit.collider != null) {
- if (hit.collider.tag == "Ground") {
- isRightSpawn = false;
- }
- } else {
- isRightSpawn = false;
- GroundClone = Instantiate (GroundPrefabe, this.transform.position + new Vector3 (1f, 0, 0), Quaternion.identity);
- }
- }
- }
- if (isLeftSpawn == true) {
- RaycastHit2D hit = Physics2D.Raycast (new Vector2 (GroundPos.x - 0.55f, GroundPos.y), new Vector2 (-0.5f, 0), 0.1f);
- if (Dis4 > 1.1f) {
- SignSelect [3].SetActive (false);
- if (hit.collider != null) {
- if (hit.collider.tag == "Ground") {
- isLeftSpawn = false;
- }
- } else {
- isLeftSpawn = false;
- GroundClone = Instantiate (GroundPrefabe, this.transform.position + new Vector3 (-1f, 0, 0), Quaternion.identity);
- }
- }
- }
- }
- void SignFade ()
- {
- if (isUpFade == false) {
- if (UpSignAlpha < 1f) {
- UpSignAlpha += 2f * Time.deltaTime;
- SignSelect [0].GetComponent<SpriteRenderer> ().color = new Color (1, 0, 0, UpSignAlpha);
- } else {
- isUpFade = true;
- }
- } else {
- if (UpSignAlpha > 0f) {
- UpSignAlpha -= 2f * Time.deltaTime;
- SignSelect [0].GetComponent<SpriteRenderer> ().color = new Color (1, 0, 0, UpSignAlpha);
- } else {
- isUpFade = false;
- }
- }
- if (isDownFade == false) {
- if (DownSignAlpha < 1f) {
- DownSignAlpha += 2f * Time.deltaTime;
- SignSelect [1].GetComponent<SpriteRenderer> ().color = new Color (1, 0, 0, DownSignAlpha);
- } else {
- isDownFade = true;
- }
- } else {
- if (DownSignAlpha > 0f) {
- DownSignAlpha -= 2f * Time.deltaTime;
- SignSelect [1].GetComponent<SpriteRenderer> ().color = new Color (1, 0, 0, DownSignAlpha);
- } else {
- isDownFade = false;
- }
- }
- if (isRightFade == false) {
- if (RightSighAlpha < 1f) {
- RightSighAlpha += 2f * Time.deltaTime;
- SignSelect [2].GetComponent<SpriteRenderer> ().color = new Color (1, 0, 0, RightSighAlpha);
- } else {
- isRightFade = true;
- }
- } else {
- if (RightSighAlpha > 0f) {
- RightSighAlpha -= 2f * Time.deltaTime;
- SignSelect [2].GetComponent<SpriteRenderer> ().color = new Color (1, 0, 0, RightSighAlpha);
- } else {
- isRightFade = false;
- }
- }
- if (isLeftFade == false) {
- if (LeftSignAlpha < 1f) {
- LeftSignAlpha += 2f * Time.deltaTime;
- SignSelect [3].GetComponent<SpriteRenderer> ().color = new Color (1, 0, 0, LeftSignAlpha);
- } else {
- isLeftFade = true;
- }
- } else {
- if (LeftSignAlpha > 0f) {
- LeftSignAlpha -= 2f * Time.deltaTime;
- SignSelect [3].GetComponent<SpriteRenderer> ().color = new Color (1, 0, 0, LeftSignAlpha);
- } else {
- isLeftFade = false;
- }
- }
- }
- void OnCollisionStay2D (Collision2D col)
- {
- if (col.gameObject.tag == "Player") {
- if ((PlayerPos.x - GroundPos.x < 0.575f && PlayerPos.x - GroundPos.x > -0.575f) && (PlayerPos.y - GroundPos.y > 0.625f)) {
- isSetUp = true;
- SignSelect [0].SetActive (true);
- }
- if ((PlayerPos.x - GroundPos.x < 0.575f && PlayerPos.x - GroundPos.x > -0.575f) && (PlayerPos.y - GroundPos.y < -0.625f)) {
- isSetDown = true;
- SignSelect [1].SetActive (true);
- }
- if (PlayerPos.x - GroundPos.x > 0.625f && (PlayerPos.y - GroundPos.y < 0.575f && PlayerPos.y - GroundPos.y > -0.575f)) {
- isSetRight = true;
- SignSelect [2].SetActive (true);
- }
- if ((PlayerPos.x - GroundPos.x < -0.625f && (PlayerPos.y - GroundPos.y < 0.575f) && PlayerPos.y - GroundPos.y > -0.575f)) {
- isSetLeft = true;
- SignSelect [3].SetActive (true);
- }
- }
- }
- void OnCollisionExit2D (Collision2D col)
- {
- if (col.gameObject.tag == "Player") {
- if (isSetUp == true) {
- isUpSpawn = true;
- isSetUp = false;
- }
- if (isSetDown == true) {
- isDownSpawn = true;
- isSetDown = false;
- }
- if (isSetRight == true) {
- isRightSpawn = true;
- isSetRight = false;
- }
- if (isSetLeft == true) {
- isLeftSpawn = true;
- isSetLeft = false;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement