Quantcast
Channel: Questions in topic: "error"
Viewing all articles
Browse latest Browse all 7934

Switch statement not working C# (answered)

$
0
0
My game creates two obstacles which can each be in one of three different positions(picked randomly). However in my game i never want them to be the same position to begin with. So using my knowledge of switch statements from the switch statement beginner tutorial i created one to change my second obstacles position to a position which was not the same as the first and was randomly decided from the other two positions. I know this sounds complex but hopefully the code will explain it, i come across what i believe are syntax errors yet the code is fine in comparison with the rules talked about in the tutorial. Below is my code and errors - using UnityEngine; using System.Collections; public class Generater2 : MonoBehaviour { public Rigidbody original; public new Vector3 startPoin; public Vector3 posOne; Vector3[] positionArra = new Vector3[3]; Vector3[] positionArr = new Vector3[3]; // Use this for initialization void Start () { InvokeRepeating("Spawn", 2.1f, 1f); positionArra[0] = new Vector3(0f,4f,100f); positionArra[1] = new Vector3(10f,4f,100f); positionArra[2] = new Vector3(-10f,4f,100f); positionArr[0] = new Vector3(0f,4f,100f); positionArr[1] = new Vector3(-10f,4f,100f); } // Update is called once per frame void Update () { startPoin = positionArra[Random.Range(0,3)]; GameObject plane = GameObject.Find("Plane"); Generater playerScript = plane.GetComponent(); posOne = playerScript.startPoint; if (posOne == startPoin) { switch (posOne) { case (-10f, 4f, 100f): startPoin = positionArra[Random.Range(0,2)]; break; case (0f, 4f, 100f): startPoin = positionArra[Random.Range(1,3)]; break; case (10f, 4f, 100f): startPoin = positionArr[Random.Range(0,2)]; break; } } } void Spawn () { Rigidbody clone = (Rigidbody)Instantiate (original, startPoin, new Quaternion (0,0,0,0)); } } Assets/Scripts/Generater2.cs(36,43): error CS1026: Unexpected symbol `,', expecting `)' Assets/Scripts/Generater2.cs(40,36): error CS1525: Unexpected symbol `case' Assets/Scripts/Generater2.cs(54,14): error CS0116: A namespace can only contain types and namespace declarations Assets/Scripts/Generater2.cs(58,1): error CS8025: Parsing error Assets/Scripts/Generater2.cs(44,36);error CS1525: Unexpected symbol 'case'

Viewing all articles
Browse latest Browse all 7934

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>