How can i use enum to pass variables between two scripts?

Hen Avrami

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

Emad

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How can I pass variables betweet two Subs in Excel VBA?

From Dev

How can i pass ENV variables between make targets

From Java

AngularJS: How can I pass variables between controllers?

From Dev

How can I pass variables between DRY templates and ncludes in Jekyll

From Dev

How can I pass around variables between handlers

From Dev

Can I pass and use enum as a variable?

From Dev

How can I pass parameters between two activities?

From Dev

How can I get the diff between two character variables in minutes

From Dev

How can I parse the information between two variables into a matrix?

From Dev

Pass a variable between two scripts?

From Dev

how can I use many .bashrc scripts?

From Dev

Can I use bash history modifiers with variables in scripts?

From Dev

What are the relationships between workspace, .m scripts and Simulink models and how can I use them efficiently?

From Dev

How can I use the fromRaw() function of enum

From Dev

How can I use an Enum for Validation in VBA

From Dev

How can I use an Enum for Validation in VBA

From Dev

How can i pass variables in Zend?

From Dev

Sharing variables between two independent shell scripts

From Dev

Sharing variables between two independent shell scripts

From Dev

How do I use custom variables in MSBuild scripts?

From Dev

How can use two variables in one loop

From Dev

How can I pass captured data between two Rundeck Job References?

From Dev

How can I pass an object between functions

From Dev

How can I pass an object between functions

From Dev

How can I pass global Meteor variables to templates and access and use them?

From Dev

How can I subtract two NSUInteger variables?

From Dev

How can I share Tampermonkey scripts between versions of Chrome?

From Dev

How can I not use argument to pass values between methods of different classes

From Dev

JavaScript - How can you pass global variables between .js files?

Related Related

  1. 1

    How can I pass variables betweet two Subs in Excel VBA?

  2. 2

    How can i pass ENV variables between make targets

  3. 3

    AngularJS: How can I pass variables between controllers?

  4. 4

    How can I pass variables between DRY templates and ncludes in Jekyll

  5. 5

    How can I pass around variables between handlers

  6. 6

    Can I pass and use enum as a variable?

  7. 7

    How can I pass parameters between two activities?

  8. 8

    How can I get the diff between two character variables in minutes

  9. 9

    How can I parse the information between two variables into a matrix?

  10. 10

    Pass a variable between two scripts?

  11. 11

    how can I use many .bashrc scripts?

  12. 12

    Can I use bash history modifiers with variables in scripts?

  13. 13

    What are the relationships between workspace, .m scripts and Simulink models and how can I use them efficiently?

  14. 14

    How can I use the fromRaw() function of enum

  15. 15

    How can I use an Enum for Validation in VBA

  16. 16

    How can I use an Enum for Validation in VBA

  17. 17

    How can i pass variables in Zend?

  18. 18

    Sharing variables between two independent shell scripts

  19. 19

    Sharing variables between two independent shell scripts

  20. 20

    How do I use custom variables in MSBuild scripts?

  21. 21

    How can use two variables in one loop

  22. 22

    How can I pass captured data between two Rundeck Job References?

  23. 23

    How can I pass an object between functions

  24. 24

    How can I pass an object between functions

  25. 25

    How can I pass global Meteor variables to templates and access and use them?

  26. 26

    How can I subtract two NSUInteger variables?

  27. 27

    How can I share Tampermonkey scripts between versions of Chrome?

  28. 28

    How can I not use argument to pass values between methods of different classes

  29. 29

    JavaScript - How can you pass global variables between .js files?

HotTag

Archive