Fixed changing shapes

- Changing shapes no longer breaks menu functions
- Moved all Change...() functions related to Player in SpinningCube.cs
to ToggleMenus.cs script
-- Add saving needed data
--Color, shape (Speed between shapes, etc..)

-Created two new functions to replace 10+ small functions with switch
case
-ChangeShape(string shape) & ChangeColor(string color)
This commit is contained in:
Shaun Reed 2017-09-06 20:05:59 -04:00
parent 22c303d686
commit 20ff747b7b
9 changed files with 183 additions and 160 deletions

Binary file not shown.

Binary file not shown.

View File

@ -1,8 +1,9 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: 00e22d1ed21d14248801d764a0f6a057 guid: 00e22d1ed21d14248801d764a0f6a057
timeCreated: 1478187146 timeCreated: 1504664152
licenseType: Free licenseType: Free
NativeFormatImporter: NativeFormatImporter:
mainObjectFileID: 100100000
userData: userData:
assetBundleName: assetBundleName:
assetBundleVariant: assetBundleVariant:

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -81,7 +81,7 @@ public class ExperienceBar : MonoBehaviour {
previousExpRequired = currentRequirement; previousExpRequired = currentRequirement;
currentExp -= previousExpRequired; currentExp -= previousExpRequired;
currentRequirement = Mathf.Pow(currentRequirement, 1.05f); currentRequirement = Mathf.Pow(currentRequirement, 1.05f);
GameObject.FindGameObjectWithTag("Player").GetComponent<SpinningCube>().RaiseRotationSpeed(); GameObject.Find("Main Panel").GetComponent<ToggleMenus>().RaiseRotationSpeed();
notify = "Level " + currentLevel + "!"; notify = "Level " + currentLevel + "!";
eventSystem.GetComponent<GameManager>().RewardPopup(currentLevel, 2); eventSystem.GetComponent<GameManager>().RewardPopup(currentLevel, 2);

View File

@ -11,27 +11,27 @@ public class SpinningCube : MonoBehaviour
public float rotationPerSec = 0.0f; public float rotationPerSec = 0.0f;
private string RotationDirection = "Up"; public string RotationDirection = "Up";
private Vector3 m_RotationDirection = Vector3.up; public Vector3 m_RotationDirection = Vector3.up;
private Vector3 rotationOrigin; public Vector3 rotationOrigin;
private Vector3 stopRotation = Vector3.zero; public Vector3 stopRotation = Vector3.zero;
private Vector3 tempRotation; public Vector3 tempRotation;
private float angle2 = 0; public float angle2 = 0;
private float angledif, angle1; public float angledif, angle1;
private float angleSum = 0; public float angleSum = 0;
[SerializeField] [SerializeField]
private float secPerRotation = 0.0f; public float secPerRotation = 0.0f;
[SerializeField] [SerializeField]
private float lastRPS = 0.0f; public float lastRPS = 0.0f;
[SerializeField] [SerializeField]
private float secondsPassed = 0.0f; public float secondsPassed = 0.0f;
[SerializeField] [SerializeField]
private int rotations; public int rotations;
public void Start() public void Start()
{ {
@ -44,98 +44,6 @@ public class SpinningCube : MonoBehaviour
} }
*/ */
} }
public void ToggleRotationDirection()
{
if (m_RotationDirection == Vector3.up)
{
m_RotationDirection = Vector3.down;
RotationDirection = "Down";
}
else
{
m_RotationDirection = Vector3.up;
RotationDirection = "Up";
}
Debug.Log("Toggled rotation direction: " + RotationDirection);
}
public void ToggleRotation()
{
Debug.Log("Stopping Rotation. Last known rotation direction: " + RotationDirection);
stopRotation = Vector3.zero;
if (m_RotationDirection == stopRotation)
{
m_RotationDirection = tempRotation;
}
else {
tempRotation = m_RotationDirection;
m_RotationDirection = stopRotation;
}
}
public void RaiseRotationSpeed()
{
currentSpeed = currentSpeed + currentIncrement;
Debug.Log("Rotation Speed: " + currentSpeed);
}
public void LowerRotationSpeed()
{
currentSpeed = currentSpeed - currentIncrement;
Debug.Log("Rotation Speed: " + currentSpeed);
}
public void ResetRotationSpeed()
{
currentSpeed = 20.0f;
Debug.Log("Rotation Speed Reset");
}
public void ChangeColorWhite()
{
GameObject.FindGameObjectsWithTag("Player");
gameObject.GetComponent<Renderer>().material.color = Color.white;
}
public void ChangeColorBlue()
{
gameObject.GetComponent<Renderer>().material.color = Color.blue;
}
public void ChangeColorBlack()
{
gameObject.GetComponent<Renderer>().material.color = Color.black;
}
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;
}
void FixedUpdate() void FixedUpdate()
{ {
//Set angle1 = eulerAngle of axis being rotated prior to applying rotation //Set angle1 = eulerAngle of axis being rotated prior to applying rotation

View File

@ -16,29 +16,31 @@ public class ToggleMenus : MonoBehaviour
//Shapes - Prefabs //Shapes - Prefabs
public GameObject player; public GameObject player;
public GameObject Square; public GameObject Cube;
public GameObject Sphere; public GameObject Sphere;
public GameObject Cylinder; public GameObject Cylinder;
public GameObject Capsule; public GameObject Capsule;
public GameObject Temp; public GameObject Temp;
public GameObject mySpawn; public GameObject mySpawn;
private string Spawn = "Spawn";
private string Active = "Cube";
//Use with lighting menu //Use with lighting menu
//private GameObject lighting = GameObject.FindGameObjectWithTag("Lighting"); //private GameObject lighting = GameObject.FindGameObjectWithTag("Lighting");
public float lightRotX, lightRotY, lightRotZ; public float lightRotX, lightRotY, lightRotZ;
private string Spawn = "Spawn";
private string Active = "Cube";
// Use this for initialization // Use this for initialization
void Start() void Start()
{ {
player = GameObject.FindGameObjectWithTag("Player"); player = GameObject.FindGameObjectWithTag("Player");
mySpawn = GameObject.Find("PlayerSpawn");
InitializeButtonArrays(); InitializeButtonArrays();
Temp = Square; Temp = Cube;
lightRotX = 0; lightRotX = 0;
lightRotY = 0; lightRotY = 0;
lightRotZ = 0; lightRotZ = 0;
@ -159,41 +161,56 @@ public class ToggleMenus : MonoBehaviour
expMenu.gameObject.SetActive(false); expMenu.gameObject.SetActive(false);
} }
public void ChangeShapeSquare() public void ChangeShape(string shape)
{ {
Instantiate(Square, mySpawn.transform.position, mySpawn.transform.rotation); switch (shape)
{
case "Cube":
Instantiate(Cube, mySpawn.transform.position, mySpawn.transform.rotation);
Debug.Log("Destroy " + Active); Debug.Log("Destroy " + Active);
Destroy(GameObject.Find(Active)); Destroy(GameObject.Find(Active));
Active = "Cube(Clone)"; Active = "Cube(Clone)";
player = GameObject.FindGameObjectWithTag("Player");
Debug.Log(Active); Debug.Log(Active);
}
public void ChangeShapeSphere() break;
{
case "Sphere":
Instantiate(Sphere, mySpawn.transform.position, mySpawn.transform.rotation); Instantiate(Sphere, mySpawn.transform.position, mySpawn.transform.rotation);
Debug.Log("Destroy " + Active); Debug.Log("Destroy " + Active);
Destroy(GameObject.Find(Active)); Destroy(GameObject.Find(Active));
Active = "Sphere(Clone)"; Active = "Sphere(Clone)";
player = GameObject.FindGameObjectWithTag("Player");
Debug.Log(Active); Debug.Log(Active);
}
public void ChangeShapeCapsule() break;
{
case "Capsule":
Instantiate(Capsule, mySpawn.transform.position, mySpawn.transform.rotation); Instantiate(Capsule, mySpawn.transform.position, mySpawn.transform.rotation);
Debug.Log("Destroy " + Active); Debug.Log("Destroy " + Active);
Destroy(GameObject.Find(Active)); Destroy(GameObject.Find(Active));
Active = "Capsule(Clone)"; Active = "Capsule(Clone)";
player = GameObject.FindGameObjectWithTag("Player");
Debug.Log(Active); Debug.Log(Active);
}
public void ChangeShapeCylinder() break;
{
case "Cylinder":
Instantiate(Cylinder, mySpawn.transform.position, mySpawn.transform.rotation); Instantiate(Cylinder, mySpawn.transform.position, mySpawn.transform.rotation);
Debug.Log("Destroy " + Active); Debug.Log("Destroy " + Active);
Destroy(GameObject.Find(Active)); Destroy(GameObject.Find(Active));
Active = "Cylinder(Clone)"; Active = "Cylinder(Clone)";
player = GameObject.FindGameObjectWithTag("Player");
Debug.Log(Active); Debug.Log(Active);
break;
default:
Debug.Log("Error - Not a valid shape : " + shape);
break;
} }
}
/* /*
public void EditLightingRotation() public void EditLightingRotation()
{ {
@ -310,25 +327,25 @@ public class ToggleMenus : MonoBehaviour
mainButtons[3].onClick.AddListener(() => { ToggleLightingMenu(); }); mainButtons[3].onClick.AddListener(() => { ToggleLightingMenu(); });
mainButtons[4].onClick.AddListener(() => { ToggleExpMenu(); }); mainButtons[4].onClick.AddListener(() => { ToggleExpMenu(); });
rotationButtons[0].onClick.AddListener(() => { player.GetComponent<SpinningCube>().RaiseRotationSpeed(); }); rotationButtons[0].onClick.AddListener(() => { RaiseRotationSpeed(); });
rotationButtons[1].onClick.AddListener(() => { player.GetComponent<SpinningCube>().LowerRotationSpeed(); }); rotationButtons[1].onClick.AddListener(() => { LowerRotationSpeed(); });
rotationButtons[2].onClick.AddListener(() => { player.GetComponent<SpinningCube>().ToggleRotation(); }); rotationButtons[2].onClick.AddListener(() => { ToggleRotation(); });
rotationButtons[3].onClick.AddListener(() => { player.GetComponent<SpinningCube>().ToggleRotationDirection(); }); rotationButtons[3].onClick.AddListener(() => { ToggleRotationDirection(); });
rotationButtons[4].onClick.AddListener(() => { player.GetComponent<SpinningCube>().ResetRotationSpeed(); }); rotationButtons[4].onClick.AddListener(() => { ResetRotationSpeed(); });
colorButtons[0].onClick.AddListener(() => { player.GetComponent<SpinningCube>().ChangeColorBlack(); }); colorButtons[0].onClick.AddListener(() => { ChangeColor("Black"); });
colorButtons[1].onClick.AddListener(() => { player.GetComponent<SpinningCube>().ChangeColorWhite(); }); colorButtons[1].onClick.AddListener(() => { ChangeColor("White"); });
colorButtons[2].onClick.AddListener(() => { player.GetComponent<SpinningCube>().ChangeColorRed(); }); colorButtons[2].onClick.AddListener(() => { ChangeColor("Red"); });
colorButtons[3].onClick.AddListener(() => { player.GetComponent<SpinningCube>().ChangeColorGreen(); }); colorButtons[3].onClick.AddListener(() => { ChangeColor("Green"); });
colorButtons[4].onClick.AddListener(() => { player.GetComponent<SpinningCube>().ChangeColorBlue(); }); colorButtons[4].onClick.AddListener(() => { ChangeColor("Blue"); });
colorButtons[5].onClick.AddListener(() => { player.GetComponent<SpinningCube>().ChangeColorYellow(); }); colorButtons[5].onClick.AddListener(() => { ChangeColor("Yellow"); });
colorButtons[6].onClick.AddListener(() => { player.GetComponent<SpinningCube>().ChangeColorCyan(); }); colorButtons[6].onClick.AddListener(() => { ChangeColor("Cyan"); });
colorButtons[7].onClick.AddListener(() => { player.GetComponent<SpinningCube>().ChangeColorMagenta(); }); colorButtons[7].onClick.AddListener(() => { ChangeColor("Magenta"); });
shapesButtons[0].onClick.AddListener(() => { ChangeShapeCylinder(); }); shapesButtons[0].onClick.AddListener(() => { ChangeShape("Cylinder"); });
shapesButtons[1].onClick.AddListener(() => { ChangeShapeCapsule(); }); shapesButtons[1].onClick.AddListener(() => { ChangeShape("Capsule"); });
shapesButtons[2].onClick.AddListener(() => { ChangeShapeSquare(); }); shapesButtons[2].onClick.AddListener(() => { ChangeShape("Cube"); });
shapesButtons[3].onClick.AddListener(() => { ChangeShapeSphere(); }); shapesButtons[3].onClick.AddListener(() => { ChangeShape("Sphere"); });
//Temporary save/load hidden in lighting for debug //Temporary save/load hidden in lighting for debug
lightingButtons[0].onClick.AddListener(() => { GameObject.Find("EventSystem").GetComponent<GameManager>().Save(); }); lightingButtons[0].onClick.AddListener(() => { GameObject.Find("EventSystem").GetComponent<GameManager>().Save(); });
@ -340,4 +357,101 @@ public class ToggleMenus : MonoBehaviour
expButtons[2].onClick.AddListener(() => { GameObject.Find("Gained Image").GetComponent<ExperienceBar>().ResetExp(); }); expButtons[2].onClick.AddListener(() => { GameObject.Find("Gained Image").GetComponent<ExperienceBar>().ResetExp(); });
} }
public void ToggleRotationDirection()
{
if (GameObject.FindGameObjectWithTag("Player").GetComponent<SpinningCube>().m_RotationDirection == Vector3.up)
{
GameObject.FindGameObjectWithTag("Player").GetComponent<SpinningCube>().m_RotationDirection = Vector3.down;
GameObject.FindGameObjectWithTag("Player").GetComponent<SpinningCube>().RotationDirection = "Down";
}
else
{
GameObject.FindGameObjectWithTag("Player").GetComponent<SpinningCube>().m_RotationDirection = Vector3.up;
GameObject.FindGameObjectWithTag("Player").GetComponent<SpinningCube>().RotationDirection = "Up";
}
Debug.Log("Toggled rotation direction: " + GameObject.FindGameObjectWithTag("Player").GetComponent<SpinningCube>().RotationDirection);
}
public void ToggleRotation()
{
Debug.Log("Stopping Rotation. Last known rotation direction: " + GameObject.FindGameObjectWithTag("Player").GetComponent<SpinningCube>().RotationDirection);
GameObject.FindGameObjectWithTag("Player").GetComponent<SpinningCube>().stopRotation = Vector3.zero;
if (GameObject.FindGameObjectWithTag("Player").GetComponent<SpinningCube>().m_RotationDirection == GameObject.FindGameObjectWithTag("Player").GetComponent<SpinningCube>().stopRotation)
{
GameObject.FindGameObjectWithTag("Player").GetComponent<SpinningCube>().m_RotationDirection = GameObject.FindGameObjectWithTag("Player").GetComponent<SpinningCube>().tempRotation;
}
else
{
GameObject.FindGameObjectWithTag("Player").GetComponent<SpinningCube>().tempRotation = GameObject.FindGameObjectWithTag("Player").GetComponent<SpinningCube>().m_RotationDirection;
GameObject.FindGameObjectWithTag("Player").GetComponent<SpinningCube>().m_RotationDirection = GameObject.FindGameObjectWithTag("Player").GetComponent<SpinningCube>().stopRotation;
}
}
public void RaiseRotationSpeed()
{
GameObject.FindGameObjectWithTag("Player").GetComponent<SpinningCube>().currentSpeed = GameObject.FindGameObjectWithTag("Player").GetComponent<SpinningCube>().currentSpeed + GameObject.FindGameObjectWithTag("Player").GetComponent<SpinningCube>().currentIncrement;
Debug.Log("Rotation Speed: " + GameObject.FindGameObjectWithTag("Player").GetComponent<SpinningCube>().currentSpeed);
}
public void LowerRotationSpeed()
{
GameObject.FindGameObjectWithTag("Player").GetComponent<SpinningCube>().currentSpeed = GameObject.FindGameObjectWithTag("Player").GetComponent<SpinningCube>().currentSpeed - GameObject.FindGameObjectWithTag("Player").GetComponent<SpinningCube>().currentIncrement;
Debug.Log("Rotation Speed: " + GameObject.FindGameObjectWithTag("Player").GetComponent<SpinningCube>().currentSpeed);
}
public void ResetRotationSpeed()
{
GameObject.FindGameObjectWithTag("Player").GetComponent<SpinningCube>().currentSpeed = 20.0f;
Debug.Log("Rotation Speed Reset");
}
public void ChangeColor(string color)
{
switch (color)
{
case "White":
GameObject.FindGameObjectWithTag("Player").GetComponent<Renderer>().material.color = Color.white;
break;
case "Blue":
GameObject.FindGameObjectWithTag("Player").GetComponent<Renderer>().material.color = Color.blue;
break;
case "Black":
GameObject.FindGameObjectWithTag("Player").GetComponent<Renderer>().material.color = Color.black;
break;
case "Green":
GameObject.FindGameObjectWithTag("Player").GetComponent<Renderer>().material.color = Color.green;
break;
case "Red":
GameObject.FindGameObjectWithTag("Player").GetComponent<Renderer>().material.color = Color.red;
break;
case "Magenta":
GameObject.FindGameObjectWithTag("Player").GetComponent<Renderer>().material.color = Color.magenta;
break;
case "Yellow":
GameObject.FindGameObjectWithTag("Player").GetComponent<Renderer>().material.color = Color.yellow;
break;
case "Cyan":
GameObject.FindGameObjectWithTag("Player").GetComponent<Renderer>().material.color = Color.cyan;
break;
default:
Debug.Log("Error - no color named :" + color);
break;
}
}
} }