The first script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WallsTest : MonoBehaviour
{
public enum WallsInfo
{
Position, Length
};
// using a GameObject rather than a transform
public GameObject prefab;
public Vector3 wallsStartPosition;
public float width = 0;
public float height = 1;
public float length = 2;
public Camera wallsCamera;
void Start()
{
wallsCamera.transform.position = new Vector3(wallsStartPosition.x, wallsStartPosition.y + 100, wallsStartPosition.z - 235);
WallsInfo.Position = wallsStartPosition;
BuildWalls();
}
Then in another position i will want to use the WallsInfo.Position But i'm not sure if passing variables using enum is a good idea ? And how to do it ?
The line:
WallsInfo.Position = wallsStartPosition;
Give me error:
The left-hand side of an assignment must be a variable, property or indexer
And i also want to pass the variable length using Length
You don't need an enum here you need a class or a struct. I bet an struct because it can't be null.
public struct WallsInfo
{
public Vector3 Position { get; set; }
public float Length { get; set; }
};
Enums on the other hand are used to store a collection of constant named values that are mapped to numbers for better organization. For example if you want to keep track of if a character is boy or a girl. Then you can just put an int and say 1 means boy 2 means girl in your head or you can do:
public enum Gender
{
Boy = 1
Girl =2
}
Then it's easy to have a character who can store boy or girl like
var gender = Gender.Boy;
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments