コード例 #1
0
 void OnTriggerEnter(Collider other)
 {
     if (other.CompareTag("EnemyBullet"))
     {
         money.reduceBy(bulletDamage);
     }
 }
コード例 #2
0
    // Update is called once per frame
    void FixedUpdate()
    {
        // Subtract money when moving
        if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.D))
        {
            movementCostDelay--;
            if (movementCostDelay <= 0)
            {
                movementCostDelay = 60;
                money.reduceBy(10);
            }
        }

        /* Player rotation is affecting movement
         *
         * RaycastHit hit;
         * Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
         *
         * if (Physics.Raycast(ray, out hit, 100))
         * {
         *  transform.LookAt(new Vector3(hit.point.x, transform.position.y, hit.point.z));
         * }*/
    }
コード例 #3
0
    // Update is called once per frame
    void Update()
    {
        // Instantiate bullets, with cooldown
        if (isFiring)
        {
            shotCounter -= Time.deltaTime;
            if (shotCounter <= 0)
            {
                shotCounter = timeBetweenShots;
                Bullet_Controller newBullet = Instantiate(bullet, firePoint.position, firePoint.rotation);
                newBullet.speed = bulletSpeed;

                money.reduceBy(bulletCost);
            }
        }
        else
        {
            shotCounter -= Time.deltaTime;
            if (shotCounter <= 0)
            {
                shotCounter = 0;
            }
        }
    }