Advertisement
moinularif

AirTimeContriller

Sep 3rd, 2015
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.79 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4.  
  5. public class AirtimeController : MonoBehaviour {
  6.  
  7.  
  8.     public  RaycastHit2D hit;
  9.     public Ray2D downRay;
  10.     LayerMask mask;
  11.     public Vector2 rayDirection;
  12.    
  13.     public bool isGrounded;
  14.  
  15.     public GameObject carBody;
  16.  
  17.     public float tempAirTimeValue;
  18.     public float speed;
  19.     public int airTimeValue;
  20.  
  21.     public List<int> airTime = new List<int>();
  22.     // Use this for initialization
  23.     void Start ()
  24.     {
  25.         isGrounded = true;
  26.         mask = LayerMask.NameToLayer("Default");
  27.        
  28.     }
  29.    
  30.     // Update is called once per frame
  31.     void Update ()
  32.     {
  33.         downRay = new Ray2D(carBody.transform.position, Vector2.down);
  34.  
  35.         Debug.DrawRay(carBody.transform.position, Vector2.down * 10000, Color.green);
  36.  
  37.  
  38.        // hit = Physics2D.Raycast(carBody.transform.position, Vector2.down);
  39.         hit = Physics2D.Raycast(carBody.transform.position, Vector2.down, mask, 0, 0);
  40.  
  41.        // Debug.Log(hit.transform.name);
  42.         if (hit.transform.name == "Hill")
  43.         {
  44.             Debug.Log("Hill Found");
  45.             if(hit.distance > 5.0f)
  46.             {
  47.                 isGrounded = false;
  48.             }
  49.             else
  50.             {
  51.                 isGrounded = true;
  52.             }
  53.         }
  54.         else
  55.         {
  56.             Debug.Log("No Hill Found");
  57.         }
  58.        
  59.         //AirTimeChange();
  60.     }
  61.  
  62.     void AirTimeChange()
  63.     {
  64.         if (!isGrounded)
  65.         {
  66.             airTimeValue = 0;
  67.             tempAirTimeValue = 0;
  68.             tempAirTimeValue = tempAirTimeValue + speed * Time.deltaTime;
  69.  
  70.         }
  71.         else
  72.         {
  73.             airTimeValue = (int)tempAirTimeValue;
  74.             Debug.Log(airTimeValue);
  75.  
  76.         }
  77.     }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement