Пример #1
0
    void fire()
    {
        RaycastHit hitInfo;

        fireTimeLeft = fireTime;

        if (currentClip > 0)
        {
            // Everytime we shoot we lose a bullet
            currentClip--;
            Debug.Log("Ammo count: " + currentClip);
            // Cast a ray from the center of the screen until it hits something, or not
            if (Physics.Raycast(Camera.main.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0)), out hitInfo))
            {
                // Spawn particle system
                GameObject go = Instantiate(hitFx);
                // Move particle system to where we shoot
                go.transform.position = hitInfo.point;
                // Point the particle system in the right direction
                go.transform.forward = hitInfo.normal;

                // Only hitting objects that are "shootable"
                Shootable hit = hitInfo.collider.GetComponent <Shootable>();
                if (hit != null)
                {
                    if (doubleDamage)
                    {
                        hit.OnHit(2);
                    }
                    else
                    {
                        hit.OnHit(1);
                    }
                }
            }
        }
        else
        {
            reload();
        }
    }
Пример #2
0
    // Update is called once per frame
    void Update()
    {
        // 각 Shootable 오브젝트의 OnHit 콜백 호출
        if (m_hitList.Count > 0)
        {
            foreach (GameObject go in m_hitList)
            {
                if (m_shootableList.Contains(go))
                {
                    Shootable shootable = go.GetComponent <Shootable>();
                    if (yukari != null)
                    {
                        shootable.OnHit(yukari);
                    }
                }
            }

            m_hitList.Clear();
        }
    }
Пример #3
0
    void Aim()
    {
        if (alive)
        {
            Vector2 minput = new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y"));
            transform.localEulerAngles += Vector3.up * minput.x * camSpeed;
            Vector3 angles = cam.localEulerAngles;
            angles -= Vector3.right * minput.y * camSpeed;
            if (angles.x > 180f && angles.x < 270f)
            {
                angles.x = 270f;
            }
            if (angles.x < 180f && angles.x > 90f)
            {
                angles.x = 90f;
            }
            cam.localEulerAngles = angles;

            // Laser
            Vector3    point = cam.position + cam.forward * 100f;
            RaycastHit hit;

            if (Physics.Raycast(shotOrigin.position, point - shotOrigin.position, out hit, 20f, ~(1 << 8)))
            {
                point = hit.point;
                if (shooting)
                {
                    Shootable hitObject = hit.transform.GetComponent <Shootable>();
                    if (hitObject != null)
                    {
                        hitObject.OnHit(hit.point);
                    }
                }
            }
            lr.SetPosition(0, shotOrigin.position);
            lr.SetPosition(1, point);
        }
    }