2. Scripts
1) Slingshot script
1-input. Getbutton function Test
Description :
Input. Getbutton ("...") is returned according to the button name true when the corresponding virtual button is pressed
Input. Getbutton ("Fire1"): determine whether to click the mouse or touch the screen
Measured:
void Update () {
BOOL Bisbuttondown = Input.getbutton ("Fire1");
if (! Clicked) {
if (Bisbuttondown) {
Print ("tap screen");
}
}
}
Effect:
Results:
function is correct
2-Collider. Raycast () function test
Description
Collider. Raycast (): Returns a Boolean (bool) value that returns true if the ray and any collider intersect ,otherwise false. That is, it returns true when the light touches any collider, otherwise false.
Specific Description:http://www.ceeger.com/Script/Collider/Collider.Raycast.html
measured :
error:"unityengine.component" does not containthe definition of "Raycast" and cannot find an acceptable type of " Unityengine.component"The first parameter of the extension method"Raycast"( whether a using directive or assembly reference ?) D:\Unity\unity01\qiezaxiaozhu\Assets\Scripts\DanGongS.cs
Results:
The function cannot be run in vs2010 , presumably removing the function for Unity 5.x . Find the Substitute function:physics.raycast
3-physics.raycast () function test
Description
Physics.raycast (): ray projection, true when Ray casts intersect with any collider, otherwise false.
Specific Description:http://www.ceeger.com/Script/Physics/Physics.Raycast.html
measurement 1:
1. true if Ray casts intersect with any collider, otherwise false.
void Update () {
BOOL Bisbuttondown = Input.getbutton ("Fire1");
if (! Clicked)
{
if (Bisbuttondown) {
Ray Ray = Camera.main.ScreenPointToRay (input.mouseposition);
Raycasthit RCH;
if (Physics.raycast (ray, out RCH, 1000.0f)) {
Print ("Collision");
}
}
}
}
result 1:
true if Ray casts intersect with any collider, otherwise false. established
Measurement 2:
since this project to lock click Slingshot for the reaction, the requirements and measured 1 does not match, so the use of his overloaded function.
1. Create a new layer for the Slingshot , (edit-project settings-tags ands layers-layers-user Layer 8- "Fasheqi" )
2. modify the layer of the catapult's preset body ,
void Update () {
BOOL Bisbuttondown = Input.getbutton ("Fire1");
if (! Clicked)
{
if (Bisbuttondown) {
Ray Ray = Camera.main.ScreenPointToRay (input.mouseposition);
Raycasthit RCH;
if (Physics.raycast (ray, out RCH, 1000.0f, 1 << 8)) {
Print ("Collision");
}
}
}
}
result 2:
Ray casts are true only when the collider crosses the "fasheqi" layer, and the others are false.
Reference pages:
[Unity3d] Ray Collision Detection +layermask use of:http://blog.sina.com.cn/s/blog_947a2cdd0102uz1k.html
"Feng Yu Chong" Unity3d Tutorial Raycast:http://www.xuebuyuan.com/2074615.html
Unity Penguin Smashing Piggy Note 2