Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Interfacing ... C#<>Unity-Game-Engine [until now not found, what I need]

Discussion in 'Getting Started' started by Nafraju, Feb 26, 2020.

  1. Nafraju

    Nafraju

    Joined:
    Feb 25, 2020
    Posts:
    2
    Hi,

    I need to know only 4 things (perhaps with scipt examples):

    1. How I get Values from the UnityEngine into C# Variables
    for ex) The current Position of ... the Player (x,y,z)

    2. How I set Values to the UnityEngine from C# Variables
    for ex) The new Position of ... the Player (x,y,z)

    3. Interacting C# with Unity-Game-Engine:
    If I click on the Play Button, then all elements of the game would be loaded with their 'Start-Values'.

    a) Is there a Function, that's recall/reset one Element to its 'Start-Values' ?
    b) Is there a Function, that's recall/reset ALL Elements (the entire Game) to its 'Start-Values' ?​

    [To 3.) I mean directly = without collecting the 'Start-Values' (1.) and set them again via (2.)]

    If I get the answer from You to all 3 Points, You will give me all help I need.

    Best Greetings & Wishes & Thanks
    Nafraju

    ######
    I am switching the last 10 years Programming Excel/Access Databases, PHP-MySQL incl C# (VStudio) ... only C#
    ... now Unity incl C#.
    [Using: Unity 2019.3.0f5 (64-bit) & Visual Studio 2017 on Win7(64)]


    Until now I have search in tutorials, google, youtube, forums ... [the last three days]
     
    Last edited: Feb 27, 2020
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,842
    I highly doubt those are all you need. It sounds like you haven't cracked the manual, and you're going to need to do that (as well as the scripting reference). But anyway:

    1. Vector3 pos = transform.position;

    2. transform.position = new Vector3(x,y,z);

    3.a) No.
    3.b) SceneManager.LoadScene(0);

    Even though you already know C#, I highly recommend you spend an afternoon going through some tutorials (click the "Learn" link at the top of this page). You need to get at least the big picture of how GameObjects and Components (including both Transform, which represents the position/scale/orientation of the game object) and your scripts all relate.
     
    Nafraju and Joe-Censored like this.
  3. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    As far as 1 & 2, you need to get the hang of getting and using references to GameObjects and their components. Then you just access their public methods and variables. I'm sure there are plenty of tutorials in this area.

    For 3a the easiest way is to destroy the GameObject and then re-instantiate the GameObject from its prefab. If you haven't learned about prefabs and instantiating them, it is an important topic. But usually when I want to reset something I just write a reset method which sets everything back to what it was originally, but I think I only really do this when dealing with object pooling.
     
  4. Bill_Martini

    Bill_Martini

    Joined:
    Apr 19, 2016
    Posts:
    445
    Go to the Learning link above. The questions you asked will be answered in the first tutorial you do. Questions you haven't asked will also be answered there too.
     
    JoeStrout likes this.
  5. Nafraju

    Nafraju

    Joined:
    Feb 25, 2020
    Posts:
    2
    Thank you for answering my post.

    Especially for JoeStrout 's answer.

    From JoeStrout 's answering my 3 points directly,
    I got the rethink (from other programming) to unity-C #,
    which I did not got by reading the manual/scripting-reference or with the working through the tutorials.

    Because: I expected the unity-game-engine to have a different (an other) logic / system than it has.

    Thank you !

    #####
     
    JoeStrout likes this.
  6. Bill_Martini

    Bill_Martini

    Joined:
    Apr 19, 2016
    Posts:
    445
    Going into any new endeavor with pre-conceived notions or expectations is a recipe for failure. There is a learning phase in anything new, don't short circuit that with unguided notions of how things work.