2017-08-22 17:29:01 +00:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
using System.Collections;
|
|
|
|
|
|
|
|
|
|
public class SpinningCube : MonoBehaviour
|
|
|
|
|
{
|
2017-09-03 22:56:05 +00:00
|
|
|
|
|
|
|
|
|
//Playerdata -- Needs saved
|
2017-09-03 23:47:23 +00:00
|
|
|
|
public float currentSpeed = 20f;
|
|
|
|
|
public float currentIncrement = 10f;
|
2017-08-22 17:29:01 +00:00
|
|
|
|
|
2017-09-03 23:47:23 +00:00
|
|
|
|
private string RotationDirection = "Up";
|
|
|
|
|
private Vector3 m_RotationDirection = Vector3.up;
|
|
|
|
|
private Vector3 rotationOrigin;
|
|
|
|
|
private Vector3 stopRotation = Vector3.zero;
|
|
|
|
|
private Vector3 tempRotation;
|
|
|
|
|
private float angle2 = 0;
|
|
|
|
|
private float angledif, angle1;
|
|
|
|
|
private float angleSum = 0;
|
2017-08-22 17:29:01 +00:00
|
|
|
|
|
2017-09-03 19:58:42 +00:00
|
|
|
|
[SerializeField]
|
2017-09-03 23:47:23 +00:00
|
|
|
|
private int rotations;
|
|
|
|
|
|
|
|
|
|
public void OnDestroy()
|
|
|
|
|
{
|
|
|
|
|
GameObject.FindGameObjectWithTag("GameController").GetComponent<GameManager>().Save();
|
|
|
|
|
}
|
2017-08-22 17:29:01 +00:00
|
|
|
|
|
2017-09-03 19:58:42 +00:00
|
|
|
|
public void ToggleRotationDirection()
|
2017-09-03 23:47:23 +00:00
|
|
|
|
{
|
2017-08-22 17:29:01 +00:00
|
|
|
|
|
2017-09-03 23:47:23 +00:00
|
|
|
|
if (m_RotationDirection == Vector3.up)
|
2017-08-22 17:29:01 +00:00
|
|
|
|
{
|
2017-09-03 23:47:23 +00:00
|
|
|
|
m_RotationDirection = Vector3.down;
|
|
|
|
|
RotationDirection = "Down";
|
2017-08-22 17:29:01 +00:00
|
|
|
|
}
|
2017-09-03 23:47:23 +00:00
|
|
|
|
else
|
2017-08-22 17:29:01 +00:00
|
|
|
|
{
|
2017-09-03 23:47:23 +00:00
|
|
|
|
m_RotationDirection = Vector3.up;
|
|
|
|
|
RotationDirection = "Up";
|
2017-08-22 17:29:01 +00:00
|
|
|
|
}
|
2017-09-03 23:47:23 +00:00
|
|
|
|
Debug.Log("Toggled rotation direction: " + RotationDirection);
|
2017-08-22 17:29:01 +00:00
|
|
|
|
|
2017-09-03 23:47:23 +00:00
|
|
|
|
}
|
2017-08-22 17:29:01 +00:00
|
|
|
|
|
2017-09-03 23:47:23 +00:00
|
|
|
|
public void ToggleRotation()
|
|
|
|
|
{
|
|
|
|
|
Debug.Log("Stopping Rotation. Last known rotation direction: " + RotationDirection);
|
|
|
|
|
stopRotation = Vector3.zero;
|
|
|
|
|
|
|
|
|
|
if (m_RotationDirection == stopRotation)
|
2017-08-22 17:29:01 +00:00
|
|
|
|
{
|
2017-09-03 23:47:23 +00:00
|
|
|
|
m_RotationDirection = tempRotation;
|
2017-08-22 17:29:01 +00:00
|
|
|
|
}
|
2017-09-03 23:47:23 +00:00
|
|
|
|
else {
|
|
|
|
|
tempRotation = m_RotationDirection;
|
|
|
|
|
m_RotationDirection = stopRotation;
|
2017-08-22 17:29:01 +00:00
|
|
|
|
}
|
2017-09-03 23:47:23 +00:00
|
|
|
|
}
|
2017-08-22 17:29:01 +00:00
|
|
|
|
|
2017-09-03 23:47:23 +00:00
|
|
|
|
public void RaiseRotationSpeed()
|
|
|
|
|
{
|
|
|
|
|
currentSpeed = currentSpeed + currentIncrement;
|
|
|
|
|
Debug.Log("Rotation Speed: " + currentSpeed);
|
|
|
|
|
}
|
2017-08-22 17:29:01 +00:00
|
|
|
|
|
2017-09-03 23:47:23 +00:00
|
|
|
|
public void LowerRotationSpeed()
|
|
|
|
|
{
|
|
|
|
|
currentSpeed = currentSpeed - currentIncrement;
|
|
|
|
|
Debug.Log("Rotation Speed: " + currentSpeed);
|
|
|
|
|
}
|
2017-08-22 17:29:01 +00:00
|
|
|
|
|
2017-09-03 23:47:23 +00:00
|
|
|
|
public void ResetRotationSpeed()
|
|
|
|
|
{
|
|
|
|
|
currentSpeed = 20.0f;
|
|
|
|
|
Debug.Log("Rotation Speed Reset");
|
|
|
|
|
}
|
2017-08-22 17:29:01 +00:00
|
|
|
|
|
2017-09-03 23:47:23 +00:00
|
|
|
|
public void ChangeColorWhite()
|
|
|
|
|
{
|
|
|
|
|
GameObject.FindGameObjectsWithTag("Player");
|
|
|
|
|
gameObject.GetComponent<Renderer>().material.color = Color.white;
|
|
|
|
|
}
|
2017-08-22 17:29:01 +00:00
|
|
|
|
|
2017-09-03 23:47:23 +00:00
|
|
|
|
public void ChangeColorBlue()
|
|
|
|
|
{
|
|
|
|
|
gameObject.GetComponent<Renderer>().material.color = Color.blue;
|
|
|
|
|
}
|
2017-08-22 17:29:01 +00:00
|
|
|
|
|
2017-09-03 23:47:23 +00:00
|
|
|
|
public void ChangeColorBlack()
|
|
|
|
|
{
|
|
|
|
|
gameObject.GetComponent<Renderer>().material.color = Color.black;
|
|
|
|
|
}
|
2017-08-22 17:29:01 +00:00
|
|
|
|
|
2017-09-03 23:47:23 +00:00
|
|
|
|
public void ChangeColorGreen()
|
|
|
|
|
{
|
|
|
|
|
gameObject.GetComponent<Renderer>().material.color = Color.green;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ChangeColorRed()
|
|
|
|
|
{
|
|
|
|
|
gameObject.GetComponent<Renderer>().material.color = Color.red;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ChangeColorMagenta()
|
|
|
|
|
{
|
|
|
|
|
gameObject.GetComponent<Renderer>().material.color = Color.magenta;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ChangeColorYellow()
|
|
|
|
|
{
|
|
|
|
|
gameObject.GetComponent<Renderer>().material.color = Color.yellow;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ChangeColorCyan()
|
|
|
|
|
{
|
|
|
|
|
gameObject.GetComponent<Renderer>().material.color = Color.cyan;
|
|
|
|
|
}
|
2017-08-22 17:29:01 +00:00
|
|
|
|
|
2017-09-03 19:58:42 +00:00
|
|
|
|
void FixedUpdate()
|
|
|
|
|
{
|
|
|
|
|
//Set angle1 = eulerAngle of axis being rotated prior to applying rotation
|
|
|
|
|
angle1 = this.gameObject.transform.rotation.eulerAngles.y;
|
2017-09-03 22:56:05 +00:00
|
|
|
|
transform.Rotate(m_RotationDirection * Time.deltaTime * currentSpeed);
|
2017-09-03 19:58:42 +00:00
|
|
|
|
//angle2 = eulerAngle of axis after rotation applied
|
|
|
|
|
angle2 = this.gameObject.transform.rotation.eulerAngles.y;
|
|
|
|
|
//Difference between angle2 and angle1, how much the object rotated between frames
|
|
|
|
|
angledif = angle2 - angle1;
|
|
|
|
|
|
|
|
|
|
//rotations += (int)(m_Speed / 360);
|
|
|
|
|
|
|
|
|
|
//if object is rotating, and angle difference is less than 0
|
2017-09-03 23:47:23 +00:00
|
|
|
|
//If object has rotated 20 degrees (currentSpeed = 20), when angle1 = 350, && angle2 = 10
|
2017-09-03 19:58:42 +00:00
|
|
|
|
//angle2(10)-angle1(350) = -340
|
|
|
|
|
//Object has rotated past 360
|
2017-09-03 22:56:05 +00:00
|
|
|
|
if ((currentSpeed > 0) && (angledif < 0))
|
2017-09-03 19:58:42 +00:00
|
|
|
|
{
|
|
|
|
|
++rotations;
|
|
|
|
|
GameObject.FindGameObjectWithTag("ExpGained").GetComponent<ExperienceBar>().ExpMore();
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-08-22 17:29:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|