Search Unity

Disabling/Enabling Script From Another Game Object C#

Discussion in 'Scripting' started by LeeDenbigh, Aug 1, 2015.

  1. LeeDenbigh

    LeeDenbigh

    Joined:
    Jul 7, 2014
    Posts:
    48
    Okay, so I have looked everywhere, there seems to be a lot of answers, but none of them are working for me, so I'm wondering if one of you geniuses can help me out.

    I have the image effect script - MotionBlur attached to my camera. It is turned off by default, as I only need it to be set to enabled when the player boosts. But I am finding that the script that is attached to the Player (PlayerController.cs) isn't recognising that I have a script called 'MotionBlur' attached to the camera.

    Camera mainCam;
    mainCam = FindObjectOfType<Camera>();
    mainCam.GetComponent<FollowTarget>().enabled = true;
    mainCam.GetComponent<MotionBlur>().enabled = false;

    I am getting an error on the 'MotionBlur' saying "The name 'MotionBlur' does not exist in the current context.

    The Script is added, but it's not recognised. But the 'FollowTarget' is working perfectly!

    Anyone know what I am doing wrong...

    Thank you.
     
  2. DonLoquacious

    DonLoquacious

    Joined:
    Feb 24, 2013
    Posts:
    1,667
    If you have a class called MotionBlur (spelling/capitalization is important) in the project and the name of the file it's in is identical to the name of the class, then the problem is likely a completely unrelated error and/or some sort of caching issue. Check the console to see if there's some other error in the project, and fix that. If not, just restart Unity maybe.
     
  3. LeeDenbigh

    LeeDenbigh

    Joined:
    Jul 7, 2014
    Posts:
    48
    The script 'MotionBlur' is a unity image effect script that comes with pro (actually I think anyone can use it now). But whereas you can call a script that you create like: PlayerController playerController; I'm not able to pick up on this MotionBlur script.

    I am also using the: using UnityStandardAssets.Utility;
    Still not finding the script on the camera. The name of the script I am using is called PlayerController, so it's not that. Plus if I add other scripts for the Image Effect folder (provided by Unity) they aren't being picked up either. Only FollowTarget... It's really bizarre.
     
  4. DonLoquacious

    DonLoquacious

    Joined:
    Feb 24, 2013
    Posts:
    1,667
    Probably the wrong namespace still, for that. Try "UnityStandardAssets.ImageEffects".
     
    LeeDenbigh likes this.
  5. LeeDenbigh

    LeeDenbigh

    Joined:
    Jul 7, 2014
    Posts:
    48
    Can't believe that mate, stupid mistake. Thank you that was what I was doing haha.