Unity Penguin Smashing Piggy Note 2

Source: Internet
Author: User
Tags unity 5

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.