Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Why am I receiving this error in unity through this line of code?

Discussion in 'Scripting' started by Bkrmalick, Jan 12, 2014.

  1. Bkrmalick

    Bkrmalick

    Joined:
    Nov 21, 2013
    Posts:
    4
  2. shaderbytes

    shaderbytes

    Joined:
    Nov 11, 2010
    Posts:
    900
    I can only imagine that the transform.Find("Capsule") did not return anything.
     
  3. THoeppner

    THoeppner

    Joined:
    Oct 10, 2012
    Posts:
    205
    Hey.

    if you want proper help for code problems it is better to paste the code itself and the full error message with the description in which line the error occurs.

    Here is a description how to use the code tags correctly: http://forum.unity3d.com/threads/143875-Using-code-tags-properly

    Otherwise we can only guess why the error occurs.
     
  4. djfunkey

    djfunkey

    Joined:
    Jul 16, 2012
    Posts:
    201
    try this:
    Code (csharp):
    1.  
    2. transform.Find("Capsule").Translate(0,0.02f,0);
    3.  
    For any value this is a decimal you need to state that it is a float, donated by the "f" after a decimel
     
  5. MDragon

    MDragon

    Joined:
    Dec 26, 2013
    Posts:
    329
    djfunkey, pretty sure that will not work still... Maybe.

    Another possible issue is that this is a cast issue as well. When using something like gameObject.Find, you have to at least store it on a temporary variable and then do anything on it. I believe this is the case for FindWithTag, and Find should be the same.

    Maybe :D If it works, please say so!
     
  6. ThermalFusion

    ThermalFusion

    Joined:
    May 1, 2011
    Posts:
    906
    Transform.Find only finds child transforms, meaning Capsule would have to be attatched to a child of the object this script is run on.
    Try:
    Code (csharp):
    1. GameObject.Find("Capsule").transform.Translate(0,0.02f,0);
     
  7. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Only if you're using C#, which the OP is not, and in any case that has nothing to do with the error.

    Nope. The answer posted by shaderbytes is correct: the script is apparently not attached to the Sphere object, because otherwise it would work.

    --Eric