browser icon
You are using an insecure version of your web browser. Please update your browser!
Using an outdated browser makes your computer unsafe. For a safer, faster, more enjoyable user experience, please update your browser today or try a newer browser.


Raycast Hit!

Hello guys! Programmer here! :D

So, after we found out that there are some problems regarding our old selecting method (yes selecting the object, what else?), we decided to research more about other possibilities regarding selection method, as this is indeed one of the most important thing in hidden-object game.

So, I decided to try out the Raycast Hit, which Mr. Alvin have tried it before and said that he got some problems regarding Raycast hit, but at that time I didn’t have the chance to really go into raycast hit, so here it is some snippet of the raycast hit:

function Update () {
   if (Input.GetMouseButton(0)) {
      var hit : RaycastHit;
      var ray : Ray = Camera.main.ScreenPointToRay(Input.mousePosition);

      if (Physics.Raycast(ray, hit, 100.0)) {
         if(hit.transform.gameObject.tag == "Cube") //do something with cube objects
         else if(hit.transform.gameObject.tag == "wrong!") // is not our target.
         // so on so forth

So far the code is working like a charm in test scene, will update you guys when we actually move this inside the game scene. Hope this helps the others. =)

Keep Coding!


Categories: Scripting | 2 Comments