daily pastebin goal
41%
SHARE
TWEET

Untitled

a guest Jun 14th, 2018 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class GrowGround : MonoBehaviour
  6. {
  7.     Vector2 PlayerPos;
  8.     Vector2 GroundPos;
  9.  
  10.     float Dis1, Dis2, Dis3, Dis4;
  11.     float UpSignAlpha = 0, DownSignAlpha = 0, RightSighAlpha = 0, LeftSignAlpha = 0;
  12.  
  13.     bool isUpSpawn = false, isDownSpawn = false, isRightSpawn = false, isLeftSpawn = false;
  14.     bool isSetUp = false, isSetDown = false, isSetRight = false, isSetLeft = false;
  15.     bool isUpFade = false, isDownFade = false, isRightFade = false, isLeftFade = false;
  16.  
  17.     public GameObject[] SignSelect;
  18.     public GameObject GroundClone;
  19.     public GameObject GroundPrefabe;
  20.  
  21.     void Start ()
  22.     {
  23.         GroundPos = new Vector2 (this.transform.position.x, this.transform.position.y);
  24.         for (int i = 0; i < SignSelect.Length; i++) {
  25.             SignSelect [i].SetActive (false);
  26.         }
  27.     }
  28.  
  29.     void Update ()
  30.     {
  31.         GroundSpawn ();
  32.         SignFade ();
  33.     }
  34.  
  35.     void GroundSpawn ()
  36.     {
  37.         PlayerPos = new Vector2 (GameObject.Find ("Player").transform.position.x, GameObject.Find ("Player").transform.position.y);
  38.         Dis1 = Vector2.Distance (new Vector2 (GroundPos.x, GroundPos.y + 1f), PlayerPos);
  39.         Dis2 = Vector2.Distance (new Vector2 (GroundPos.x, GroundPos.y - 1f), PlayerPos);
  40.         Dis3 = Vector2.Distance (new Vector2 (GroundPos.x + 1f, GroundPos.y), PlayerPos);
  41.         Dis4 = Vector2.Distance (new Vector2 (GroundPos.x - 1f, GroundPos.y), PlayerPos);
  42.         if (isUpSpawn == true) {
  43.             RaycastHit2D hit = Physics2D.Raycast (new Vector2 (GroundPos.x, GroundPos.y + 0.55f), new Vector2 (0, 0.5f), 0.1f);
  44.             if (Dis1 > 1f) {
  45.                 SignSelect [0].SetActive (false);
  46.                 if (hit.collider != null) {
  47.                     if (hit.collider.tag == "Ground") {
  48.                         isUpSpawn = false;
  49.                     }
  50.                 } else {
  51.                     isUpSpawn = false;
  52.                     GroundClone = Instantiate (GroundPrefabe, this.transform.position + new Vector3 (0, 1f, 0), Quaternion.identity);
  53.                 }
  54.             }
  55.         }
  56.         if (isDownSpawn == true) {
  57.             RaycastHit2D hit = Physics2D.Raycast (new Vector2 (GroundPos.x, GroundPos.y - 0.55f), new Vector2 (0, -0.5f), 0.1f);
  58.             if (Dis2 > 1f) {
  59.                 SignSelect [1].SetActive (false);
  60.                 if (hit.collider != null) {
  61.                     if (hit.collider.tag == "Ground") {
  62.                         isDownSpawn = false;
  63.                     }
  64.                 } else {
  65.                     isDownSpawn = false;
  66.                     GroundClone = Instantiate (GroundPrefabe, this.transform.position + new Vector3 (0, -1f, 0), Quaternion.identity);
  67.                 }
  68.             }
  69.         }
  70.         if (isRightSpawn == true) {
  71.             RaycastHit2D hit = Physics2D.Raycast (new Vector2 (GroundPos.x + 0.55f, GroundPos.y), new Vector2 (0.5f, 0), 0.1f);
  72.             if (Dis3 > 1.1f) {
  73.                 SignSelect [2].SetActive (false);
  74.                 if (hit.collider != null) {
  75.                     if (hit.collider.tag == "Ground") {
  76.                         isRightSpawn = false;
  77.                     }
  78.                 } else {
  79.                     isRightSpawn = false;
  80.                     GroundClone = Instantiate (GroundPrefabe, this.transform.position + new Vector3 (1f, 0, 0), Quaternion.identity);
  81.                 }
  82.             }
  83.         }
  84.         if (isLeftSpawn == true) {
  85.             RaycastHit2D hit = Physics2D.Raycast (new Vector2 (GroundPos.x - 0.55f, GroundPos.y), new Vector2 (-0.5f, 0), 0.1f);
  86.             if (Dis4 > 1.1f) {
  87.                 SignSelect [3].SetActive (false);
  88.                 if (hit.collider != null) {
  89.                     if (hit.collider.tag == "Ground") {
  90.                         isLeftSpawn = false;
  91.                     }
  92.                 } else {
  93.                     isLeftSpawn = false;
  94.                     GroundClone = Instantiate (GroundPrefabe, this.transform.position + new Vector3 (-1f, 0, 0), Quaternion.identity);
  95.                 }
  96.             }
  97.         }
  98.     }
  99.  
  100.     void SignFade ()
  101.     {
  102.         if (isUpFade == false) {
  103.             if (UpSignAlpha < 1f) {
  104.                 UpSignAlpha += 2f * Time.deltaTime;
  105.                 SignSelect [0].GetComponent<SpriteRenderer> ().color = new Color (1, 0, 0, UpSignAlpha);
  106.             } else {
  107.                 isUpFade = true;
  108.             }
  109.         } else {
  110.             if (UpSignAlpha > 0f) {
  111.                 UpSignAlpha -= 2f * Time.deltaTime;
  112.                 SignSelect [0].GetComponent<SpriteRenderer> ().color = new Color (1, 0, 0, UpSignAlpha);
  113.             } else {
  114.                 isUpFade = false;
  115.             }
  116.         }
  117.  
  118.         if (isDownFade == false) {
  119.             if (DownSignAlpha < 1f) {
  120.                 DownSignAlpha += 2f * Time.deltaTime;
  121.                 SignSelect [1].GetComponent<SpriteRenderer> ().color = new Color (1, 0, 0, DownSignAlpha);
  122.             } else {
  123.                 isDownFade = true;
  124.             }
  125.         } else {
  126.             if (DownSignAlpha > 0f) {
  127.                 DownSignAlpha -= 2f * Time.deltaTime;
  128.                 SignSelect [1].GetComponent<SpriteRenderer> ().color = new Color (1, 0, 0, DownSignAlpha);
  129.             } else {
  130.                 isDownFade = false;
  131.             }
  132.         }
  133.  
  134.         if (isRightFade == false) {
  135.             if (RightSighAlpha < 1f) {
  136.                 RightSighAlpha += 2f * Time.deltaTime;
  137.                 SignSelect [2].GetComponent<SpriteRenderer> ().color = new Color (1, 0, 0, RightSighAlpha);
  138.             } else {
  139.                 isRightFade = true;
  140.             }
  141.         } else {
  142.             if (RightSighAlpha > 0f) {
  143.                 RightSighAlpha -= 2f * Time.deltaTime;
  144.                 SignSelect [2].GetComponent<SpriteRenderer> ().color = new Color (1, 0, 0, RightSighAlpha);
  145.             } else {
  146.                 isRightFade = false;
  147.             }
  148.         }
  149.  
  150.         if (isLeftFade == false) {
  151.             if (LeftSignAlpha < 1f) {
  152.                 LeftSignAlpha += 2f * Time.deltaTime;
  153.                 SignSelect [3].GetComponent<SpriteRenderer> ().color = new Color (1, 0, 0, LeftSignAlpha);
  154.             } else {
  155.                 isLeftFade = true;
  156.             }
  157.         } else {
  158.             if (LeftSignAlpha > 0f) {
  159.                 LeftSignAlpha -= 2f * Time.deltaTime;
  160.                 SignSelect [3].GetComponent<SpriteRenderer> ().color = new Color (1, 0, 0, LeftSignAlpha);
  161.             } else {
  162.                 isLeftFade = false;
  163.             }
  164.         }
  165.     }
  166.  
  167.     void OnCollisionStay2D (Collision2D col)
  168.     {
  169.         if (col.gameObject.tag == "Player") {
  170.  
  171.             if ((PlayerPos.x - GroundPos.x < 0.575f && PlayerPos.x - GroundPos.x > -0.575f) && (PlayerPos.y - GroundPos.y > 0.625f)) {
  172.                 isSetUp = true;
  173.                 SignSelect [0].SetActive (true);
  174.             }
  175.  
  176.             if ((PlayerPos.x - GroundPos.x < 0.575f && PlayerPos.x - GroundPos.x > -0.575f) && (PlayerPos.y - GroundPos.y < -0.625f)) {
  177.                 isSetDown = true;
  178.                 SignSelect [1].SetActive (true);
  179.             }
  180.  
  181.             if (PlayerPos.x - GroundPos.x > 0.625f && (PlayerPos.y - GroundPos.y < 0.575f && PlayerPos.y - GroundPos.y > -0.575f)) {
  182.                 isSetRight = true;
  183.                 SignSelect [2].SetActive (true);   
  184.             }
  185.             if ((PlayerPos.x - GroundPos.x < -0.625f && (PlayerPos.y - GroundPos.y < 0.575f) && PlayerPos.y - GroundPos.y > -0.575f)) {
  186.                 isSetLeft = true;
  187.                 SignSelect [3].SetActive (true);
  188.             }
  189.         }
  190.     }
  191.  
  192.     void OnCollisionExit2D (Collision2D col)
  193.     {
  194.         if (col.gameObject.tag == "Player") {
  195.             if (isSetUp == true) {
  196.                 isUpSpawn = true;
  197.                 isSetUp = false;
  198.             }
  199.             if (isSetDown == true) {
  200.                 isDownSpawn = true;
  201.                 isSetDown = false;
  202.             }
  203.             if (isSetRight == true) {
  204.                 isRightSpawn = true;
  205.                 isSetRight = false;
  206.             }
  207.             if (isSetLeft == true) {
  208.                 isLeftSpawn = true;
  209.                 isSetLeft = false;
  210.             }
  211.         }
  212.     }
  213. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top