Ejemplo n.º 1
0
    public void Shoot()
    {
        // Raycast method to determine the object hit. Droids lose health and rockets
        // get destroyed.
        muzzleFlash1.Play();
        muzzleFlash2.Play();
        gunSound.Play();
        RaycastHit hit;

        if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit))
        {
            DroidController  droid  = hit.transform.GetComponent <DroidController>();
            RocketController rocket = hit.transform.GetComponent <RocketController>();

            if (hit.transform.tag == "Droid")
            {
                droid.TakeDamage(damage);
                currentScore += droidScoreValue;
            }
            if (hit.transform.tag == "Rocket")
            {
                rocket.TakeDamage(damage);
                currentScore += rocketScoreValue;
            }
        }
        GameObject impact = Instantiate(impactEffect, hit.point, Quaternion.LookRotation(hit.normal));

        impact.GetComponent <ParticleSystem>().Play();
        Destroy(impact, 2f);
    }
Ejemplo n.º 2
0
    void Spawn()
    {
        // Choose a random spawn
        float      randomRotation = Random.value * Mathf.PI * 2;
        Vector3    spawnLocation  = new Vector3(Mathf.Cos(randomRotation) * 10, .5f + Random.value * 3, Mathf.Sin(randomRotation) * 10);
        GameObject droid          = Instantiate(TrainingDroidPrefab, spawnLocation, Quaternion.identity);

        mDroids.Add(droid);

        DroidController droidController = droid.GetComponent <DroidController>();

        droidController.Player = Player;

        if (Mode == GameMode.Survival)
        {
            droidController.mIsAttackDroid = true;
        }
    }
Ejemplo n.º 3
0
 public override void AddToGame(Game game)
 {
     this.nodeList        = Service.EntityController.GetNodeList <DroidNode>();
     this.droidController = Service.DroidController;
 }
Ejemplo n.º 4
0
    private void DebugModePlacementUpdate()
    {
#if UNITY_EDITOR
        float horAxis      = Input.GetAxis("Horizontal");
        bool  pressedLeft  = Input.GetKeyDown(KeyCode.LeftBracket);
        bool  pressedRight = Input.GetKeyDown(KeyCode.RightBracket);
        bool  pressedUp    = Input.GetKeyDown(KeyCode.Semicolon);
        bool  pressedDown  = Input.GetKeyDown(KeyCode.Comma);
        bool  pressedX     = Input.GetKeyDown(KeyCode.LeftShift);
        bool  pressedY     = Input.GetKeyDown(KeyCode.Tab);
#else
        m_xboxController.Update();
        float horAxis      = m_xboxController.GetAxisLeftThumbstickX();
        bool  pressedLeft  = m_xboxController.GetButtonDown(ControllerButton.DPadLeft);
        bool  pressedRight = m_xboxController.GetButtonDown(ControllerButton.DPadRight);
        bool  pressedUp    = m_xboxController.GetButtonDown(ControllerButton.DPadUp);
        bool  pressedDown  = m_xboxController.GetButtonDown(ControllerButton.DPadDown);
        bool  pressedX     = m_xboxController.GetButtonDown(ControllerButton.X);
        bool  pressedY     = m_xboxController.GetButtonDown(ControllerButton.Y);
#endif

        // Y toggles placement mode
        if (pressedY)
        {
            m_player.gameObject.SetActive(!m_player.gameObject.activeSelf);
        }
        if (m_player.gameObject.activeSelf)
        {
            m_placeableObjects[m_objectIdx].SetActive(false);
            return;
        }

        // Up/down change the placement mode
        if (pressedUp)
        {
            uint mode = (uint)m_placementMode;
            mode            = (mode + 1) % (int)PlacementMode.NumPlacementModes;
            m_placementMode = (PlacementMode)mode;
        }
        if (pressedDown)
        {
            uint mode = (uint)m_placementMode;
            mode            = (mode - 1) % (uint)PlacementMode.NumPlacementModes;
            m_placementMode = (PlacementMode)mode;
        }

        // Digital left/right change the object
        m_placeableObjects[m_objectIdx].SetActive(false);
        int next = (pressedLeft ? -1 : 0) + (pressedRight ? 1 : 0);
        m_objectIdx += next;
        if (m_objectIdx >= m_placeableObjects.Length)
        {
            m_objectIdx = 0;
        }
        else if (m_objectIdx < 0)
        {
            m_objectIdx = m_placeableObjects.Length - 1;
        }

        // Analog left/right changes rotation about the Y axis
        float rotateBy = (horAxis > 0.25f ? 90 : 0) + (horAxis < -0.25f ? -90 : 0);
        m_eulerY += rotateBy * Time.deltaTime;

        // Update object position based on placement mode
        GameObject preview = m_placeableObjects[m_objectIdx];
        preview.SetActive(true);
        switch (m_placementMode)
        {
        case PlacementMode.Free:
            preview.transform.position = Camera.main.transform.position + Camera.main.transform.forward;
            preview.transform.rotation = Quaternion.LookRotation(Camera.main.transform.forward, Camera.main.transform.up);
            break;

        case PlacementMode.Surface:
            preview.SetActive(false); // don't want raycast to hit self
            RaycastHit hit;
            if (FindGazeTarget(out hit))
            {
                preview.transform.position = hit.point;
                preview.transform.rotation = Quaternion.FromToRotation(Vector3.up, hit.normal) * Quaternion.Euler(new Vector3(0, m_eulerY, 0));
            }
            preview.SetActive(true);
            break;
        }

        // Place object
        if (pressedX)
        {
            GameObject newObj = Instantiate(placeablePrefabs[m_objectIdx], preview.transform.position, preview.transform.rotation);
            m_objects.Add(newObj);
            // Hack for passing player position to certain objects
            DroidController droid = newObj.GetComponent <DroidController>();
            if (droid != null)
            {
                droid.SetPlayer(m_player.gameObject);
            }
            BayController bay = newObj.GetComponent <BayController>();
            if (bay != null)
            {
                bay.SetPlayer(m_player.gameObject);
            }
        }
    }