Page 97 - MODUL PEMROGRAMAN 2D DAN 3D FIX
P. 97

38. Jika burung melewati pipa makan poin akan dijumlahkan, maka perbarui

                               script  ini  ke  dalam  script  birdcontroler  nya  agar  poin  bisa  berjalan  dan
                               bersuara.

                               using UnityEngine;

                               using System.Collections;



                               public class birdcontrol :
                                 MonoBehaviour { public
                                 Vector2 loncat = new
                                 Vector2(0,200); public score
                                 scoreman;

                                 public int
                                 poin = 1;
                                 public
                                 AudioClip
                                 musik;

                                      // Use this for
                                      initialization
                                      void Start () {

                                   scoreman =
                               GameObject.FindGameObjectWithTag("poin").GetComponent<score>();

                                      }


                                      // Update is called
                                      once per frame void
                                      Update () {

                                   if (Input.GetMouseButtonDown(0))
                                   {

                                     GetComponent<Rigidbody2D>().velocity =
                                     Vector2.zero;
                                     GetComponent<Rigidbody2D>().AddForce
                                     (loncat);

                                   }
                                      }

                                 void die()

                                 {
                                                                                                     83
                                   Application.LoadLevel(Application.loadedLevel);

                                 }
                                 void OnCollisionEnter2D(Collision2D other)
   92   93   94   95   96   97   98   99   100   101   102