Example #1
0
    // Update is called once per frame
    void Update()
    {
        if (em == null)
        {
            em = GameObject.Find("EchoManager").GetComponent <EchoManager>();
        }

        if (spawnEchos)
        {
            timeSinceLastEcho += Time.deltaTime;
            if (timeSinceLastEcho > timeBetweenEchos)
            {
                spawnTime = 0.0f;
                GameObject  temp = em.spawnAnEchoLocation(gameObject.transform.position);
                EchoSpawner t    = temp.GetComponent <EchoSpawner>();
                //Debug.Log(gameObject.name + ": "+ t.getEchoLocation());
                t.echoColor = echoColor;
                t.maxRadius = maxRadius;
                t.fade      = fade;
                t.echoSpeed = speed;

                timeSinceLastEcho = 0.0f;
                ++numEchoSpawned;
                if (numEchoSpawned > numEchos)
                {
                    timeSinceLastEcho = float.MaxValue;
                    numEchoSpawned    = 0;
                    spawnEchos        = false;
                }
            }
        }
    }
    void UpdateIsAttacking()
    {
        //Spawn Echo
        if (Input.GetMouseButtonDown(1))
        {
            Ray        ray = ((Camera)followingCamera.GetComponent <Camera>()).ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit, Mathf.Infinity, 1 << 9))
            {
                EchoSpawner echo = EchoManage.GetComponent <EchoManager>().spawnAnEchoLocation(hit.point).GetComponent <EchoSpawner>();
                echo.echoSpeed = 7.5f;
                echo.maxRadius = 15.0f;
                echo.fadeRate  = 1.5f;
            }
        }
        //Attacking
        if (!attacking && !returning && Input.GetMouseButtonDown(0))
        {
            Debug.Log("Attacking");
            Ray        ray = ((Camera)followingCamera.GetComponent <Camera>()).ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit, Mathf.Infinity))
            {
                float angle = 0.0f;
                float y     = 0.0f;
                float x     = 0.0f;
                y     = hit.point.z - transform.position.z;
                x     = hit.point.x - transform.position.x;
                angle = Mathf.Atan(y / x);
                if (x < 0)
                {
                    angle += (Mathf.PI / 2);
                    angle += (Mathf.PI / 2);
                }

                Attack(angle);
            }
        }

        if (returning)
        {
            //Debug.Log("Returning");
            if ((position - physicalBody.transform.position).magnitude < 1)
            {
                position  = physicalBody.transform.position;
                returning = false;
                AttackObject.GetComponent <TrailRenderer>().enabled = false;
                AttackObject.GetComponent <MeshRenderer>().enabled  = false;
            }
        }
    }
Example #3
0
    // Update is called once per frame
    void Update()
    {
        if (em == null)
        {
            em = GameObject.Find("EchoManager").GetComponent <EchoManager>();
        }

        spawnTime += Time.deltaTime;
        if (spawnTime >= intervalTimeOfEchos)
        {
            spawnTime = 0.0f;
            GameObject  temp = em.spawnAnEchoLocation(gameObject.transform.position);
            EchoSpawner t    = temp.GetComponent <EchoSpawner>();
            //Debug.Log(gameObject.name + ": "+ t.getEchoLocation());
            t.echoColor = echoColor;
            t.maxRadius = maxRadius;
            t.fade      = fade;
            t.echoSpeed = speed;
        }
    }