// TODO: DELETION? public void RespawnTile() { onBeat = DJ_Util.activateWithNoSound(gameObject.GetComponent <DJ_BeatActivation>()); if (onBeat) { while (tilePool.Count > 0) { TileNode poolTile = tilePool.Pop(); poolTile.tile.SetActive(true); tileMap.Add(new DJ_Point((int)poolTile.tile.transform.position.x, (int)poolTile.tile.transform.position.z), poolTile); poolTile.tile.GetComponent <DJ_TileScript>().fadeIn = true; (poolTile.tile.transform.GetChild(0).GetComponent(typeof(MeshRenderer)) as MeshRenderer).GetComponent <Renderer>().sharedMaterial.SetFloat("_Alpha", 0.0f); (poolTile.tile.transform.GetChild(0).GetComponent(typeof(MeshRenderer)) as MeshRenderer).GetComponent <Renderer>().sharedMaterial.SetFloat("_GlowStrength", 0.5f); } } }
// Update is called once per frame void Update() { laserTilePos.X = Mathf.RoundToInt(laser.transform.position.x); laserTilePos.Y = Mathf.RoundToInt(laser.transform.position.z); //Debug.Log("laser tile pos = " + laserTilePos); Vector3 _temp = lightSource.position; _temp.y = laser.transform.position.y; lightSource.position = _temp; Vector3 _dir = (laser.transform.position - lightSource.position).normalized; _dir.y = 0.0f; targetSource.position = lightSource.position + _dir * lengthOfBeam; layerOn = DJ_Util.isLayerOn(gameObject.GetComponent <DJ_BeatActivation>()); if (layerOn) { //laser.GetComponent<MeshRenderer>().enabled = true; laser.GetComponent <BoxCollider>().enabled = true; lightSource.GetComponent <ParticleRenderer>().enabled = true; } onBeat = DJ_Util.activateWithNoSound(gameObject.GetComponent <DJ_BeatActivation>()); //if (DJ_BeatManager.thresholdStartNote) if (onBeat) { changeLaserDirection(); } else { //laser.transform.rotation = Quaternion.Slerp(laser.transform.rotation, rotationVector.transform.rotation, Time.deltaTime); //var newRotation = Quaternion.LookRotation(laser.transform.position + rotationVector.position, Vector3.up); //laser.transform.rotation = Quaternion.Slerp(laser.transform.rotation, newRotation, Time.deltaTime); /* * if (currentAngle <= targetAngle) * { * laser.transform.RotateAround(transform.position, Vector3.up, 3); * currentAngle += 3; * if (currentAngle > 360) * currentAngle = 0; * Debug.Log("Current angle is " + currentAngle); * } * else * { * Debug.Log("DONE"); * } */ } if (DJ_TileManagerScript.tileMap.ContainsKey(laserTilePos)) { if (laser.GetComponent <BoxCollider>().enabled) { DJ_TileManagerScript.tileMap[laserTilePos].tile.transform.GetChild(0).GetComponent <Renderer>().material.SetFloat("_GlowStrength", 10.5f); //DJ_TileManagerScript._recentlyLaserVisitedTiles.Add(laserTilePos); //set the time remaining of the effect //DJ_TileManagerScript._tileLaserGlowTimes.Add(laserTilePos, 1.5f); } } }
//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); */ }
// Update is called once per frame public override void Update() { // GLOW when laser hovers over if (_meshRender.GetComponent <Renderer>().material.GetFloat("_GlowStrength") > .5f) { float gStrength = transform.GetChild(0).GetComponent <MeshRenderer>().GetComponent <Renderer>().sharedMaterial.GetFloat("_GlowStrength"); //tileMaterial.color = Color.Lerp(tileMaterial.color, originalColor, fadeInSpeed * Time.deltaTime); float gs = Mathf.Lerp(gStrength, 1.0f, 3 * Time.deltaTime); _meshRender.GetComponent <Renderer>().material.SetFloat("_GlowStrength", gs); } else { _meshRender.GetComponent <Renderer>().material.SetFloat("_GlowStrength", 0.5f); } base.Update(); if (!gameObject.GetComponent <DJ_Damageable>().invulnerable) { onBeat = DJ_Util.activateWithNoSound(gameObject.GetComponent <DJ_BeatActivation>()); if (onBeat) { //DJ_TileManagerScript.tilePool.Push(DJ_TileManagerScript.tileMap[new DJ_Point((int)transform.position.x, (int)transform.position.z)]); //DJ_TileManagerScript.tileMap.Remove(new DJ_Point((int)transform.position.x, (int)transform.position.z)); //gameObject.SetActive(false); startDelayTimer = true; } } if (startDelayTimer) { currentTimer += Time.deltaTime; if (currentTimer > timerDelayMax) { DJ_TileManagerScript.tilePool.Push(DJ_TileManagerScript.tileMap[new DJ_Point((int)transform.position.x, (int)transform.position.z)]); DJ_TileManagerScript.tileMap.Remove(new DJ_Point((int)transform.position.x, (int)transform.position.z)); gameObject.SetActive(false); startDelayTimer = false; currentTimer = 0; } } //save the current position of the GO so that we can //modify it and set the transform.position equal to //the modified position currentPosition = transform.position; if (fadeIn) { if (fadingTile) { if (transform.GetChild(0).GetComponent <MeshRenderer>().enabled == false) { if (DJ_Util.isLayerOn(gameObject.GetComponent <DJ_BeatActivation>())) { transform.GetChild(0).GetComponent <MeshRenderer>().enabled = true; } } } float currAlpha = transform.GetChild(0).GetComponent <MeshRenderer>().GetComponent <Renderer>().sharedMaterial.GetFloat("_Alpha"); //tileMaterial.color = Color.Lerp(tileMaterial.color, originalColor, fadeInSpeed * Time.deltaTime); float a = Mathf.Lerp(currAlpha, 1.0f, fadeInSpeed * Time.deltaTime); _meshRender.GetComponent <Renderer>().sharedMaterial.SetFloat("_Alpha", a); if (currAlpha == 1) { fadeIn = false; } } transform.position = currentPosition; }