Advertisement
JonneOpettaja

GroundHitCheck

Feb 4th, 2019
505
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.93 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class GroundHitCheck : MonoBehaviour {
  5.  
  6.     //tarkistus onko objekti maassa eli grounded
  7.     public bool isGrounded = false;
  8.  
  9.     //Tyhjällä gameobjektilla määritetään objektin reunat/keskus
  10.     public Transform GroundCheck1;
  11.     //public Transform GroundCheck2; //Käytä ylläolevan rinnalla viereistä koodia jos tarkistettava kohde suorakulmio
  12.  
  13.     //Layeri missä overLap havaitaan
  14.     public LayerMask ground_layers;
  15.  
  16.     //Itse tarkistuksen fysiikka
  17.     void FixedUpdate(){
  18.         //tarkistaa tuleeko tyhjällä peliobjektilla overlap 'ground_Layers':n kanssa yhden yksikön säteellä
  19.         isGrounded = Physics2D.OverlapCircle(GroundCheck1.position, 1, ground_layers);
  20.  
  21.         //Käytä alla olevaa koodia ylläolevan sijasta jos kohde esim suorakulmio
  22.         //isGrounded = Physics2D.OverlapArea(GroundCheck1.position, GroundCheck2.position, ground_layers);
  23.  
  24.         Debug.Log("Grounded: "+isGrounded);
  25.  
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement