-1

I have a main camera in my scene with a Sun Shafts (Script) ImageEffect on it.

[![enter image description here][1]][1]

(I'm using Medieval Environment asset.)

I'd like to disable this effect programmatically when main camera reaches a specific coordinate.

Please kkep in mind, that the script I'd like to disable is a .js script.

So here is my code:

foreach(Camera c in GameObject.FindObjectsOfType(typeof(Camera))) 
{
    if ((c.name == "Main Camera"))
    {
        if ((c.transform.position.x < -10))
        {
        //Disable Sun Shafts effect
        }
    }
}

How to disable Sun Shafts effect programmatically?

Fattie
  • 27,874
  • 70
  • 431
  • 719
Fract
  • 323
  • 1
  • 6
  • 22
  • 1
    Just an unrelated comment, Fract. You should not be using unityscript. It's only realistic to use c# these days. Forget unityscript and try c# (it's actually easier, anyway). – Fattie Jan 17 '16 at 00:19
  • Why are you saying `private ImageEffects mySunShaft;` and not simply `private SunShafts mySunShaft;`? Was SunShafts derived from some ImageEffects component? – Bart Jan 17 '16 at 02:24
  • 3
    I'm voting to close this question as off-topic because THIS IS NOT A TUTORIAL SITE, WHERE NOVICE HOBBYIST PROGRAMMERS CAN GO BACK AND FORE BEING TUTORED IN THE MOST BASIC SKILLS. – Fattie Jan 17 '16 at 15:59
  • 4
    @JoeBlow: Yet you chose to encourage more such questions by answering it? – Lightness Races in Orbit Jan 17 '16 at 16:45
  • @Bart: Tried "private SunShafts mySunShaft;" as well. It drops following exception: "Error CS0246: The type or namespace name 'SunShafts' could not be found (are you missing a using directive or an assembly reference?) (CS0246) (Assembly-CSharp)" – Fract Jan 17 '16 at 18:53
  • You simply can't *change questions by editing them* here, so I rolled it back (as someone should have done straight away). Do not hesitate to ASK NEW QUESTIONS, you're allowed to. – Fattie Jan 18 '16 at 01:58

1 Answers1

1

If you google "Unity3d disable a component" you will instantly find the answer

https://unity3d.com/learn/tutorials/modules/beginner/scripting/enabling-disabling-components

yourComponent.enabled = false;

For example this flawless answer by one of the best Unity engineers, is basically perfect

http://answers.unity3d.com/answers/26849/view.html

Note for example "If you see a checkbox in the Inspector, you can enable or disable it."

Note that here on StackOverflow you cannot change questions by editing them -- don't hesitate to ask new questions. Ask as many as you wish.

Fattie
  • 27,874
  • 70
  • 431
  • 719
  • 2
    The edit gives the answer, as does this answer. What is the problem you're still facing? If you don't understand the code provided, it's probably best to pick up a good book on C# and learn about some of the basics of the language. – Bart Jan 17 '16 at 01:32
  • The example in the edited section uses a script called "Light" so the code looks like this: "private Light myLight;" However I do not use "Light" but a script called "SunShafts.js" which displays in Unity as "Sun Shafts (Script)". I've tried to change the code above (change "Light" to "SunShaft") however the compiler fails with errors. Why? How to change the code to make it work with Sun Shafts as well? – Fract Jan 17 '16 at 01:39
  • 1
    How did you actually change your code, and what are the errors you get when doing so? – Bart Jan 17 '16 at 01:56
  • Please see Edit #2. The error I get: "The type or namespace name SunShaft could not be found..." – Fract Jan 17 '16 at 02:18
  • 2
    If it says exactly that, make sure you've written `SunShafts` (plural) because that from your screenshot seems to be the actual name. – Bart Jan 17 '16 at 02:25
  • I've doublechecked (and corrected the code part in my original comment): I use "SunShafts" everywhere in my code. The issue remains: "The type or namespace name SunShaft could not be found..." – Fract Jan 17 '16 at 10:29
  • @JoeBlow: QUIT SHOUTING AT PEOPLE. Also, the phrase you're looking for is "back and forth". – Lightness Races in Orbit Jan 17 '16 at 16:45
  • @Joe Blow: I will immediately accept your answer once you update your answer with a working code section. Sorry, I cannot do anything with your "theoritcal answer". Your answer is not an answer for .js scripts. Please answer why "private SunShafts mySunShaft;" drops following exception: "Error CS0246: The type or namespace name 'SunShafts' could not be found (are you missing a using directive or an assembly reference?) (CS0246) (Assembly-CSharp)"? Please keep in mind, that I'm working on a C# code and I'm trying to handle a .js script within the C# code. This is not a novice job. – Fract Jan 17 '16 at 19:18
  • 1
    you realise you need something along the lines `using UnityStandardAssets.ImageEffects;` – Fattie Jan 17 '16 at 19:51
  • did you think to google "unity3d SunShafts code" example http://answers.unity3d.com/questions/754418/modify-sunshafts-from-c.html – Fattie Jan 17 '16 at 19:52
  • you realise this is a Pro-license only feature btw? – Fattie Jan 17 '16 at 19:52
  • 1
    Ah, StandardAssets live in their own namespace now? I was unaware of that. Never use them really :D – Bart Jan 17 '16 at 19:59