Below is my script for rotating a game object according to angles given by a text-file. My thought is to read the text-file in the void Start() and store it into an array. My script is below and the error messages down under.
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.IO;
using UnityEngine;
var fileName = "azimuthAngles.txt";
float[] azimuth;
public class Rotate : MonoBehaviour
{
void Start()
{
var sr = new StreamReader("C: \\Users\\linnl\\OneDrive - NTNU\\Marin5autumn\\AR - Project" + "/" + fileName);
var fileContents = sr.ReadToEnd();
sr.Close();
var lines = fileContents.Split("\n"[0]);
int i;
foreach (string line in lines)
{
azimuth[i] = Convert.ToSingle(line);
i += 1;
}
//transform.RotateAround(transform.position, Vector3.up, azimuth[0] );
}
void Update()
{
/int elapsedTime_int = (int)(Time.time);
transform.RotateAround(transform.position, Vector3.up, azimuth(elapsedTime_int * 15 + 2));
}
}
[\code]
Your line numbers are a bit off. I’m not sure where you are missing a semicolon in the first error. Please try to make them fit between the error messages and your posted code example. For now here are a couple fixes (line numbers for current example):
In line 34 you wrote /int. Remove the slash there.
In line 35 you are writing azimuth(). Your azimuth, as declared in line 11, is an array tho, so you probably meant to write azimuth[ ], like you did in like 26. Otherwise the compiler thinks azimuth is supposed to be a method.
Some of the other errors may be follow up errors by the confused compiler. So fix those two and report back.
Also, especially as a beginner i would consider not using ‘var’ for everything. Fill in the proper types. That makes debugging and learning a lot easier. Everything is strongly typed in C# but ‘var’ just kinda makes you not think about types. I personally rarely use ‘var’ and mostly as a convenience tool, when type names got very long and i want to improve readability.
I’d recommend not declaring all your variables as “var”, as it makes your code less readable. Yes I know the type can be determined by the context, but still less readable especially when you’re getting someone else’s help with it. My 2 cents