This is a creation in Article, where the information may have evolved or changed.
I didn't even guess I had 2.
Last talk about how to make Pikachu appear in "Reality".
This time, we're going to take the elf ball and catch the PI-mound! (PA pa
1. Create a sphere as a sprite ball, and then on the map. Ah! We're setting it up too big to feel like we can just drop the pickup. 2333
2. Next we are going to throw out the elf ball, which is actually a simple shooting game.
① record the position of the sprite ball first.
void Span class= "Hljs-title" style= "Color:rgb (38,139,210)" >startset ( ) { Debug.Log ( "set Sprite ball Position" ); Resetpos = ball.transform.localPosition;}
② according to the finger swipe, that is, click on the place and the finger to leave the place, to determine a force
void Update () {if (input . Getmousebuttondown (0 )) {downposx = input . mouseposition.x; Downposy = INPUT.MOUSEPOSITION.Y; } if (Input.getmousebuttonup (0)) {upposx = input . mouseposition.x; Upposy = INPUT.MOUSEPOSITION.Y; Shootend (); }}
③ gives the elf ball a force to shoot out
void Span class= "Hljs-title" style= "Color:rgb (38,139,210)" >shootend () { Targetcube.transform.position = new Vector3 (( UPPOSX-DOWNPOSX) * 0.1f , (upposy-downposy) * 0.05f , (upposy-downposy) * 0.1f ); Ball. Getcomponent<rigidbody> (). Velocity = targetcube.transform.position;}
④ if not shot, let the elf ball back to the beginning of the position
void Span class= "Hljs-title" style= "Color:rgb (38,139,210)" >resetball ( ) {this . Transform.rotation = Quaternion.euler ( Vector3.zero); Ball. Getcomponent<rigidbody> (). Velocity = Vector3.zero; Ball. Getcomponent<rigidbody> (). usegravity = false ; Ball.transform.localPosition = Resetpos; }
3. But pokeball to have a heavy feeling, after hitting Pikachu, the sprite shaking in the sprite ball animation.
① add rigibody, tick off use Gravity
② to Pokeball add animator, add animation, is actually k a simple rotation around the z-axis animation.
Did you catch it?
4. To make the elf ball hit Pikachu.
① Adding a collision body
② Add collision logic to Pokeball, hide Pikachu, play Sprite ball shake animation, play catch effect
void Span class= "Hljs-title" style= "Color:rgb (38,139,210)" >oncollisionenter ( Collision Collisioninfo ) {if (Colli SionInfo.gameObject.name = = "Pikachucosplay" ) { Pikachu. SetActive (false ); Getcomponent<animator> (). Enabled = true ; Effects. SetActive (true ); } }
-----------End------------
Come and catch your pikachu!
Welcome to shoot Bricks, praise ~
Beta apk (Android 5.1 +): Http://pan.baidu.com/s/1slaQ6ID