コード例 #1
0
    void OnTriggerEnter2D(Collider2D other)
    {
        PhoneIcon phoneIcon  = other.gameObject.GetComponent <PhoneIcon>();
        Obstacle  myObstacle = other.gameObject.GetComponent <Obstacle>();
        CoinIcon  coinIcon   = other.gameObject.GetComponent <CoinIcon>();

        if (phoneIcon)
        {
            float value = phoneIcon.value;
            GameObject.Destroy(other.gameObject);
            phoneScore.addScore(value);
            phoneSlider.value += phoneIcon.value;
            Debug.Log("slider value: " + phoneSlider.value);
        }
        else if (myObstacle)
        {
            PlayerPrefs.SetFloat("phone_runner_score", phoneScore.getScore());
            Application.LoadLevel("game_over_scene");
        }
        else if (coinIcon)
        {
            float value = coinIcon.value;
            GameObject.Destroy(other.gameObject);
            coinAudio.PlayOneShot(coinSound);
            phoneScore.addScore(value);
        }
    }
コード例 #2
0
    // Update is called once per frame
    void Update()
    {
        float current_time = Time.time;

        if (current_time - lastCoinSpawnTime > 1.0)
        {
            //height and width of camera - used to determine where to spawn food
            float camHeight = Camera.main.orthographicSize;
            float camWidth  = camHeight * Camera.main.aspect;

            //gets a random location relative to camera boundaries
            Vector3  spawn_loc_vector = new Vector3(Random.Range(15, 19), Random.Range(-1, 2));
            CoinIcon newIcon          = (CoinIcon)GameObject.Instantiate(coinIcon, spawn_loc_vector, new Quaternion());
            newIcon.initialize(this);
            lastCoinSpawnTime = Time.time;
        }

        if (current_time - lastPhoneSpawnTime > 1.5)
        {
            //height and width of camera - used to determine where to spawn food
            float camHeight = Camera.main.orthographicSize;
            float camWidth  = camHeight * Camera.main.aspect;

            //gets a random location relative to camera boundaries
            Vector3   spawn_loc_vector = new Vector3(Random.Range(15, 19), Random.Range(-1, 2));
            PhoneIcon newIcon          = (PhoneIcon)GameObject.Instantiate(phoneIcon, spawn_loc_vector, new Quaternion());
            newIcon.initialize(this);
            lastPhoneSpawnTime = Time.time;
        }

        if (current_time - lastObstacleSpawnTime > 2)
        {
            //height and width of camera - used to determine where to spawn food
            float camHeight = Camera.main.orthographicSize;
            float camWidth  = camHeight * Camera.main.aspect;

            //gets a random location relative to camera boundaries
            Vector3  spawn_loc_vector = new Vector3(BOX_SPAWN_POSX, Random.Range(-4, -2));
            Obstacle newObstacle      = (Obstacle)GameObject.Instantiate(obstacle, spawn_loc_vector, new Quaternion());
            newObstacle.initialize(this);
            lastObstacleSpawnTime = Time.time;
        }
    }
コード例 #3
0
 public void removeCoinIcon(CoinIcon removeMe)
 {
     GameObject.Destroy(removeMe.gameObject);
 }