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

What am i doing wrong?[Solved]

Discussion in 'Scripting' started by keepthachange, Jun 5, 2016.

  1. keepthachange

    keepthachange

    Joined:
    Oct 15, 2014
    Posts:
    87
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
     
    Last edited: Jun 5, 2016
  2. aer0ace

    aer0ace

    Joined:
    May 11, 2012
    Posts:
    1,513
    Looks good to me. What do you think you're doing wrong?

    EDIT:
    Actually, wait, do you need to add != null to that null check?
     
  3. JasonBricco

    JasonBricco

    Joined:
    Jul 15, 2013
    Posts:
    956
    Well, what's the problem? Help people help you.
     
  4. JasonBricco

    JasonBricco

    Joined:
    Jul 15, 2013
    Posts:
    956
    There's not enough information given to know if your collisions are set up properly. It may not be doing anything because it's not registering the collision at all. Is the SloMo script on an object with a trigger collider (trigger set to true)? Is your collision matrix set to allow collisions between the layer on the SloMo object and on the character controller object?

    You should use the debugger or at least Debug.Log to figure out what's going on. Put a print inside of the on trigger enter to see if it's being called or not. If not, then you know your problem is with how you set your collisions up. If so, see if it's finding the component. Is it returning null? Put an else statement with a Debug.Log and see if that's running.

    That sort of information can help narrow down the problem.
     
  5. JasonBricco

    JasonBricco

    Joined:
    Jul 15, 2013
    Posts:
    956
    Ah, yes. Your script defines a class inside of the class and makes an instance of it within. You have to access the component and then access the instance of the CharacterMotorMovement class defined inside.

    I suppose you would want to say

    Code (CSharp):
    1. GetComponent<CharacterMotorC>().movement.maxForwardSpeed = 2.0f;
     
  6. JasonBricco

    JasonBricco

    Joined:
    Jul 15, 2013
    Posts:
    956
    What's on line 11? Doesn't seem to match your post. Is the component (from the other collider) null? Null for a component means it's not attached to the game object.
     
  7. JasonBricco

    JasonBricco

    Joined:
    Jul 15, 2013
    Posts:
    956
    One thing you're doing is you're checking to see if the object that entered the trigger has the character motor, and if so, you're changing the character motor of the object that has the SloMo script.

    Perhaps you meant to say;

    other.GetComponent<...>()...

    after the if condition.

    You had that in your first post but removed it, possibly since I didn't include it in my example (I wasn't putting the complete code).
     
  8. JasonBricco

    JasonBricco

    Joined:
    Jul 15, 2013
    Posts:
    956
    Glad you figured it out :).
     
    keepthachange likes this.
  9. JasonBricco

    JasonBricco

    Joined:
    Jul 15, 2013
    Posts:
    956
    I don't think there's an official way to mark it solved, other than putting [Solved] in the title. That should be good enough.
     
    keepthachange likes this.