Quantcast
Channel: Answers by "Graham-Dunnett"
Viewing all articles
Browse latest Browse all 959

Answer by Graham Dunnett

$
0
0
Listen very carefully, because this takes a bit of explaining. `Transform` is a class. The `Transform` class has some member functions that belong to all instances of `Transform`. The documentation describes these as "Static Functions", see: http://docs.unity3d.com/Documentation/ScriptReference/Transform.html So, for example, you can call `Transform.Destroy()` to destroy things. A different example would be the `GameObject.FindObjectOfType()` call. In both examples you're using the class name and calling a function on it. This is different from how you usually call functions, by giving an object to the left of the dot. Actually another super example is the `Input.GetButtonUp()` that you have in your code. `GetButtonUp` is a static member of `Input`. So, if there is not a `position` member of the class `Transform` what is there? Well, there is a documented variable called `position` but it's not a static member. Because it's not a static member it can only be used on an object. So, if you have: Transform fred; later in your code you can do: Debug.Log(fred.position); `Fred` is an instance of `Transform` so you can get it's `position`. Which brings me to your problem, which is you have a capital `T` in your code. A `GameObject` has a `Transform` member called `transform` (lower-case `t`). If you use the capital `T` then you mean the static member of the class. If you use the lower case `t` then you mean the variable called `transform` which just happens to be a `Transform`.

Viewing all articles
Browse latest Browse all 959

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>