Exemple #1
0
    // Update is called once per frame
    void Update()
    {
        /*
         * layerOn = DJ_Util.isLayerOn(gameObject.GetComponent<DJ_BeatActivation>());
         * if (layerOn)
         * {
         *  gameObject.GetComponent<MeshRenderer>().enabled = true;
         *  gameObject.GetComponent<BoxCollider>().enabled = true;
         * }
         * onBeat = DJ_Util.activateWithNoSound(gameObject.GetComponent<DJ_BeatActivation>());
         */

        if (_activationScript.instrument1)
        {
            fadeOutSpeed = DJ_BeatManager.GetNextLayerOneOn();;
        }
        if (_activationScript.instrument2)
        {
            fadeOutSpeed = DJ_BeatManager.GetNextLayerTwoOn();;
        }
        if (_activationScript.instrument3)
        {
            fadeOutSpeed = DJ_BeatManager.GetNextLayerThreeOn();;
        }
        if (_activationScript.instrument4)
        {
            fadeOutSpeed = DJ_BeatManager.GetNextLayerFourOn();;
        }

        onBeat = DJ_Util.activateWithSound(gameObject.GetComponent <DJ_BeatActivation>());
        if (onBeat)
        {
            gameObject.GetComponent <Renderer>().material.SetFloat("_Alpha", 1);
            gameObject.GetComponent <Renderer>().material.SetFloat("_GlowStrength", 2);
            //goes to target when it reaches its target then shrink
            HOTween.To(transform, .2f, target.OnComplete(Shrink));
            retracting = false;
            //gameObject.renderer.material = dangerShader;
        }

        if (fadeOut)
        {
            currAlpha        = gameObject.GetComponent <Renderer>().material.GetFloat("_Alpha");
            lerpA            = Mathf.Lerp(currAlpha, fadeOutAlpha, fadeOutSpeed * Time.deltaTime);
            currGlowStrength = gameObject.GetComponent <Renderer>().material.GetFloat("_GlowStrength");
            lerpG            = Mathf.Lerp(currGlowStrength, fadeOutGlow, fadeOutSpeed * Time.deltaTime);
            gameObject.GetComponent <Renderer>().material.SetFloat("_Alpha", lerpA);
            gameObject.GetComponent <Renderer>().material.SetFloat("_GlowStrength", lerpG);
        }
    }
Exemple #2
0
 private void Shrink()
 {
     if (gameObject.GetComponent <DJ_BeatActivation>().instrument1)
     {
         HOTween.To(transform, DJ_BeatManager.GetNextLayerOneOn(), origin);
     }
     else if (gameObject.GetComponent <DJ_BeatActivation>().instrument2)
     {
         HOTween.To(transform, DJ_BeatManager.GetNextLayerTwoOn(), origin);
     }
     else if (gameObject.GetComponent <DJ_BeatActivation>().instrument3)
     {
         HOTween.To(transform, DJ_BeatManager.GetNextLayerThreeOn(), origin);
     }
     else if (gameObject.GetComponent <DJ_BeatActivation>().instrument4)
     {
         HOTween.To(transform, DJ_BeatManager.GetNextLayerFourOn(), origin);
     }
     retracting = true;
     fadeOut    = true;
     //gameObject.renderer.material = safeShader;
 }
Exemple #3
0
    //void OnEnable()
    //{
    //    //UnityEditor.EditorApplication.update += Animate;
    //    laserGO.transform.parent = this.transform;
    //    Wall1.transform.parent = this.transform;
    //    Wall2.transform.parent = this.transform;

    //    Position = (EndPos + StartPos) / 2;

    //    Debug.Log("Enabling lazer animation");
    //}

    //void OnDisable()
    //{
    //    UnityEditor.EditorApplication.update -= Animate;
    //    Debug.Log("Disabling lazer animation");
    //}

    /// <summary>
    /// do the in editor animation
    /// </summary>
    public void Animate()
    {
        //calc the vector perpendicular to the direction of the animation path
        Vector3 right = Vector3.Cross(Dir, Vector3.up);

        //change the positions of the walls based on the gap distance
        //and offset part of the scale
        Wall1.transform.position = Position - right * (gapDist / 2 + Wall1.transform.localScale.x / 2)
                                   + Vector3.up * heightOffGround;
        Wall2.transform.position = Position + right * (gapDist / 2 + Wall2.transform.localScale.x / 2)
                                   + Vector3.up * heightOffGround;

        lightSource.position = Wall1.transform.position;
        target.position      = Wall2.transform.position;

        //make sure the laser object is centered between the walls
        laserGO.transform.position = (Wall2.transform.position + Wall1.transform.position) / 2;


        //set the scale of the laser so that it spans the distance betweens the  walls
        Vector3 scale = laserGO.transform.localScale;

        scale.y = (Vector3.Distance(Wall1.transform.position, Wall2.transform.position) - Wall1.transform.localScale.x) / 2;

        laserGO.transform.localScale = scale;

        laserTilePos.X = Mathf.RoundToInt(laserGO.transform.position.x);
        laserTilePos.Y = Mathf.RoundToInt(laserGO.transform.position.z);

        layerOn = DJ_Util.isLayerOn(gameObject.GetComponent <DJ_BeatActivation>());
        if (layerOn)
        {
            laserGO.GetComponent <MeshRenderer>().enabled         = true;
            laserGO.GetComponent <CapsuleCollider>().enabled      = true;
            lightSource.GetComponent <ParticleRenderer>().enabled = true;
        }

        onBeat = DJ_Util.activateWithNoSound(gameObject.GetComponent <DJ_BeatActivation>());
        if (moving == false && onBeat == true)
        {
            moving = true;

            if (gameObject.GetComponent <DJ_BeatActivation>().instrument1)
            {
                timeTillNextBeat = DJ_BeatManager.GetNextLayerOneOn();
            }
            else if (gameObject.GetComponent <DJ_BeatActivation>().instrument2)
            {
                timeTillNextBeat = DJ_BeatManager.GetNextLayerTwoOn();
            }
            else if (gameObject.GetComponent <DJ_BeatActivation>().instrument3)
            {
                timeTillNextBeat = DJ_BeatManager.GetNextLayerThreeOn();
            }
            else if (gameObject.GetComponent <DJ_BeatActivation>().instrument4)
            {
                timeTillNextBeat = DJ_BeatManager.GetNextLayerFourOn();
            }
        }

        if (moving)
        {
            currAnimationTime += Time.deltaTime;
            // Go to starting Position
            if (easeOut)
            {
                Position = Vector3.Lerp(Position, startPos, currAnimationTime * timeTillNextBeat);
                if (Vector3.Distance(Position, startPos) < .001f)
                //if (currAnimationTime > animationTime)
                {
                    currAnimationTime = 0.0f;
                    easeOut           = false;
                    easeIn            = true;
                    Position          = startPos;
                    moving            = false;
                }
            }
            // go to ending position
            else if (easeIn)
            {
                Position = Vector3.Lerp(Position, endPos, currAnimationTime * timeTillNextBeat);
                if (Vector3.Distance(Position, endPos) < .001f)
                //if (currAnimationTime > animationTime)
                {
                    currAnimationTime = 0.0f;
                    easeOut           = true;
                    easeIn            = false;
                    Position          = endPos;
                    moving            = false;
                }
            }
        }

        // GLOW when laser hovers over

        if (DJ_TileManagerScript.tileMap.ContainsKey(laserTilePos))
        {
            if (laserGO.GetComponent <CapsuleCollider>().enabled)
            {
                DJ_TileManagerScript.tileMap[laserTilePos].tile.transform.GetChild(0).GetComponent <Renderer>().material.SetFloat("_GlowStrength", 10.5f);
            }
        }

        /*
         * if (prevLaserTilePos.X > laserTilePos.X)
         * {
         *  int distanceX = prevLaserTilePos.X - laserTilePos.X;
         *  if (distanceX > 1)
         *  {
         *      Debug.Log("distanceX1 = " + distanceX);
         *      for (int j = 0; j < distanceX; j++)
         *      {
         *          DJ_Point temp = new DJ_Point(prevLaserTilePos.X + j + 1, prevLaserTilePos.Y);
         *          if (DJ_TileManagerScript.tileMap.ContainsKey(temp))
         *          {
         *              DJ_TileManagerScript.tileMap[temp].tile.transform.GetChild(0).renderer.material.SetFloat("_GlowStrength", 10.5f);
         *          }
         *      }
         *  }
         * }
         * else if (laserTilePos.X > prevLaserTilePos.X)
         * {
         *  int distanceX = laserTilePos.X - prevLaserTilePos.X;
         *  if (distanceX > 1)
         *  {
         *      Debug.Log("distanceX2 = " + distanceX);
         *      for (int j = 0; j < distanceX; j++)
         *      {
         *          DJ_Point temp = new DJ_Point(laserTilePos.X + j + 1, laserTilePos.Y);
         *          if (DJ_TileManagerScript.tileMap.ContainsKey(temp))
         *          {
         *              DJ_TileManagerScript.tileMap[temp].tile.transform.GetChild(0).renderer.material.SetFloat("_GlowStrength", 10.5f);
         *          }
         *      }
         *  }
         * }
         *
         * if (prevLaserTilePos.Y > laserTilePos.Y)
         * {
         *  int distanceZ = prevLaserTilePos.Y - laserTilePos.Y;
         *  Debug.Log("distanceZ1 = " + distanceZ);
         *  if (distanceZ > 1)
         *  {
         *      Debug.Log("distanceZ1 = " + distanceZ);
         *      for (int j = 0; j < distanceZ; j++)
         *      {
         *          DJ_Point temp = new DJ_Point(prevLaserTilePos.X, prevLaserTilePos.Y + j + 1);
         *          if (DJ_TileManagerScript.tileMap.ContainsKey(temp))
         *          {
         *              DJ_TileManagerScript.tileMap[temp].tile.transform.GetChild(0).renderer.material.SetFloat("_GlowStrength", 10.5f);
         *          }
         *      }
         *  }
         * }
         * else if (laserTilePos.Y > prevLaserTilePos.Y)
         * {
         *  int distanceZ = laserTilePos.Y - prevLaserTilePos.Y;
         *  Debug.Log("distanceZ1 = " + distanceZ);
         *  if (distanceZ > 1)
         *  {
         *      Debug.Log("distanceZ2 = " + distanceZ);
         *      for (int j = 0; j < distanceZ; j++)
         *      {
         *          DJ_Point temp = new DJ_Point(laserTilePos.X, laserTilePos.Y + j + 1);
         *          if (DJ_TileManagerScript.tileMap.ContainsKey(temp))
         *          {
         *              DJ_TileManagerScript.tileMap[temp].tile.transform.GetChild(0).renderer.material.SetFloat("_GlowStrength", 10.5f);
         *          }
         *      }
         *  }
         * }
         * Debug.Log("previous = " + prevLaserTilePos);
         * prevLaserTilePos = laserTilePos;
         *
         * Debug.Log("current = " + laserTilePos);
         */
    }