Home > other >  Ray detection based tower defense but not achieve them why
Ray detection based tower defense but not achieve them why

Time:09-20

If (Input. GetMouseButtonDown (0))
{
If (Tower!=null)
{
Ray Ray=Camera. Main. ScreenPointToRay (Input. MousePosition);
RaycastHit hit;
If (Physics. Raycast (ray, out hit, 1000, LayerMask. GetMask (" TowerBase ")))
{
To Instantiate (Tower, hit. The transform. The position, Quaternion. Identity);

}
}
The else
{
return;
}

CodePudding user response:

http://blog.csdn.net/weixin_37658157/article/details/76164101
Don't know how on earth did you not achieve them, tower defense game that I've done, but you can look at my blog, there is a notice about the X-ray testing points

CodePudding user response:

You output the collision body (hit) what is the tag or name
Probably you want to target before the collision collision with other objects

CodePudding user response:

LayerMask. GetMask (" TowerBase ")
This should be:
LayerMask. NameToLayer (" TowerBase ")
?

CodePudding user response:

I said is wrong, but I don't have permission to edit, and delete this post, I'm sorry,

CodePudding user response:

To Instantiate (Tower, hit. The transform. The position, Quaternion. Identity);
Hit. The transform. The position should be hit. Point
The first one is that you click on the pivot point position of the object, you click on the location, is at the back of the tower of your original code is created by clicking the object's pivot point, not created in the location of the mouse click, may your camera just can't see, but inside the layers panel should be able to see more come out an object,

CodePudding user response:

. Use a Debug Log () to test whether entered the instantiation statement, click on whether there after instantiation prefabricated Tower body, if no problem appeared on behalf of the code itself, look at the upstairs,
  • Related