Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- IEnumerator InteractionCheck()
- {
- //Variables
- string names = "Name";
- string ins = " Instance";
- string sm = "";
- var gr = Grass.name + ins;
- var dr = Dirt.name + ins;
- var st = Stone.name + ins;
- RaycastHit hit;
- var direction = Quaternion.AngleAxis(angle, transform.right) * transform.forward;
- var TilesP = Eyes.transform.position;
- if (Physics.Raycast(TilesP, direction, out hit, distance))
- {
- if (hit.collider != null)
- {
- names = hit.transform.name;
- selected = hit.transform.gameObject;
- sm = selected.GetComponent<MeshFilter>().mesh.name;
- }
- }
- Debug.DrawRay(TilesP, direction, Color.blue);
- if (CanSwing)
- {
- if (Input.GetKey("e"))
- {
- if(LastObjectHit != selected)
- {
- if (LastObjectHit != null)
- {
- LastObjectHit.GetComponent<Renderer>().material.color = Color.white;
- }
- LastObjectHit = selected;
- } else if (LastObjectHit)
- {
- LastObjectHit = null;
- }
- selected.GetComponent<Renderer>().material.color = Color.yellow;
- }
- if (Input.GetKeyUp("e"))
- {
- if(LastObjectHit != null) LastObjectHit.GetComponent<Renderer>().material.color = Color.white;
- Debug.Log("I'm not empty! I just hit " + names);
- Debug.Log("Its mesh was " + sm);
- if (sm == gr) HitGrass();
- if (sm == st) HitStone();
- if (sm == dr) HitDirt();
- }
- }
- yield return new WaitForSeconds(0.1f);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement