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. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

what does transform in this script refer to?

Discussion in 'Scripting' started by Pixelbyte04, Jan 9, 2018.

  1. Pixelbyte04

    Pixelbyte04

    Joined:
    Jul 30, 2017
    Posts:
    2
    I have a script like this:
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Movement : MonoBehaviour {
    5.    public float speed = 5f;
    6.    void Update() {
    7.       transform.Translate(speed * Time.deltaTime, 0, 0);
    8.    }
    9. }
    What does transform in this script refer to? Is it the transform of the GameObject that the script is attached to? I don't see any variables called transform declared in the script.
    Thanks for your help.
     
  2. ArachnidAnimal

    ArachnidAnimal

    Joined:
    Mar 3, 2015
    Posts:
    1,727
    Yes. All gameobjects have one and only one Transform component attached to them.
     
    Pixelbyte04 and TaleOf4Gamers like this.
  3. TaleOf4Gamers

    TaleOf4Gamers

    Joined:
    Nov 15, 2013
    Posts:
    825
    Just as a bit of trivia, there also used to be 'rigidbody' but that was deprecated, presumably because not every GameObject has a Rigidbody. However, transform has stayed as this is something every GameObject has.
     
  4. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    Kiwasi and TaleOf4Gamers like this.
  5. Nigey

    Nigey

    Joined:
    Sep 29, 2013
    Posts:
    1,129
    There must have been a few removed. I need to use the new keyword not just for rigidbody, but for audio, and some other random variable names.
     
  6. ArachnidAnimal

    ArachnidAnimal

    Joined:
    Mar 3, 2015
    Posts:
    1,727
    The others are: rigidbody, rigidbody2D, camera, light animation, constantForce, renderer, audio, guiText, networkView, guiElement, guiTexture, collider, hingeJoint, particleEmitter, particleSystem

    You can download ILSpy and browse the UnityEngine.dll to see what is going on:
    Code (csharp):
    1.  
    2. [Obsolete("Property rigidbody has been deprecated. Use GetComponent<Rigidbody>() instead. (UnityUpgradable)", true)]
    3.         public Component rigidbody
    4.         {
    5.             get
    6.             {
    7.                 throw new NotSupportedException("rigidbody property has been deprecated");
    8.             }
    9.         }
    10.  
     
    Nigey and TaleOf4Gamers like this.
  7. Nigey

    Nigey

    Joined:
    Sep 29, 2013
    Posts:
    1,129
    I use this right now: https://github.com/MattRix/UnityDecompiled
     
  8. ArachnidAnimal

    ArachnidAnimal

    Joined:
    Mar 3, 2015
    Posts:
    1,727
    Not sure what the value is of someone putting all that on Github. It's useless (to me) since someone (me) can just use ILSpy.
     
    Last edited: Jan 10, 2018
  9. DonLoquacious

    DonLoquacious

    Joined:
    Feb 24, 2013
    Posts:
    1,667
    It's just a convenience thing- using ILSpy is easy, but just checking a git repo (there are several) is even easier. I've done both, but usually use the latter when I want to check something quickly.

    Familiarizing yourself with ILSpy is a good idea in any case though, since it's useful for far more than Unity's assemblies, and the repos don't contain multiple assembly versions anyways so they may differ slightly from the version actually being used in your project.

    *shrugs*
     
    Ryiah likes this.
  10. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    And lets not forget its general usefulness for pulling other peoples games apart and seeing how they work. Unity games are notoriously poor on code security. So if you have the time to figure out which way is up in someone else's code, you can figure out how any mechanic is implemented in a unity game.
     
    Ryiah likes this.
  11. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    20,091
    Starting with Unity 2018.1 Windows and Mac standalones will be getting support for IL2CPP. Reverse engineering games that make use of it will become something largely done by people trying to cheat and not by people like us who want to see how a technique was done.

    https://unity3d.com/unity/beta#notes
     
    Last edited: Jan 11, 2018
    Kiwasi likes this.