Advertisement
Guest User

Slamerz

a guest
Jul 26th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.91 KB | None | 0 0
  1.      IEnumerator InteractionCheck()
  2.      {
  3.          //Variables
  4.          string names = "Name";
  5.          string ins = " Instance";
  6.          string sm = "";
  7.          var gr = Grass.name + ins;
  8.          var dr = Dirt.name + ins;
  9.          var st = Stone.name + ins;
  10.          RaycastHit hit;
  11.          var direction = Quaternion.AngleAxis(angle, transform.right) * transform.forward;
  12.          var TilesP = Eyes.transform.position;
  13.          if (Physics.Raycast(TilesP, direction, out hit, distance))
  14.          {
  15.                  if (hit.collider != null)
  16.                  {
  17.  
  18.                      names = hit.transform.name;
  19.                      selected = hit.transform.gameObject;
  20.                      sm = selected.GetComponent<MeshFilter>().mesh.name;
  21.  
  22.                  }
  23.          }
  24.          Debug.DrawRay(TilesP, direction, Color.blue);
  25.  
  26.          if (CanSwing)
  27.          {
  28.              if (Input.GetKey("e"))
  29.              {
  30.                  if(LastObjectHit != selected)
  31.                  {
  32.                      if (LastObjectHit != null)
  33.                      {
  34.                          LastObjectHit.GetComponent<Renderer>().material.color = Color.white;
  35.                      }
  36.                      LastObjectHit = selected;
  37.                  } else if (LastObjectHit)
  38.                  {
  39.                      LastObjectHit = null;
  40.                  }
  41.                  selected.GetComponent<Renderer>().material.color = Color.yellow;
  42.  
  43.              }
  44.              if (Input.GetKeyUp("e"))
  45.              {
  46.                  if(LastObjectHit != null) LastObjectHit.GetComponent<Renderer>().material.color = Color.white;
  47.                  Debug.Log("I'm not empty! I just hit " + names);
  48.                  Debug.Log("Its mesh was " + sm);
  49.                  if (sm == gr) HitGrass();
  50.                  if (sm == st) HitStone();
  51.                  if (sm == dr) HitDirt();
  52.                  
  53.              }
  54.          }
  55.          yield return new WaitForSeconds(0.1f);
  56.      }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement