How to disable sunshaft effect on my main camera? - c#

I have a main camera in my scene with a Sun Shafts (Script) ImageEffect on it.
(I'm using Medieval Environment asset.)
I'd like to disable this effect programmatically when main camera reaches a specific coordinate.
Here is my C# script's code:
using UnityEngine;
using System.Collections;
using System;
public class EnableComponents : MonoBehaviour
{
private SunShafts mySunShafts; //<<< Error CS0246 displays here (see below)
void Start ()
{
mySunShafts = GetComponent<SunShafts>();
}
void Update ()
{
foreach(Camera c in GameObject.FindObjectsOfType(typeof(Camera)))
{
if ((c.name == "Main Camera"))
{
if ((c.transform.position.x < -10))
{
mySunShafts.enabled = false;
}
}
}
}
Here is how SunShafts' code starts:
#script ExecuteInEditMode
#script RequireComponent (Camera)
#script AddComponentMenu ("Image Effects/Sun Shafts")
enum SunShaftsResolution {
Low = 0,
Normal = 1,
High = 2,
}
enum ShaftsScreenBlendMode {
Screen = 0,
Add = 1,
}
class SunShafts extends PostEffectsBase
{
public var resolution : SunShaftsResolution = SunShaftsResolution.Normal;
public var screenBlendMode : ShaftsScreenBlendMode = ShaftsScreenBlendMode.Screen;
...
...
...
When I try to debug the code, following errormessage displays:
"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)"
Here you can see that SunShaft effect and the above written C# script belongs to the same camera. However (and this is my problem) the two scripts just "cannot see each other".
So what am I doing wrong? Why my C# script "cannot see" the Sun Shafts script written in JavaScript? How should I change my C# code to be able to disable the SunShafts effect on my camera in runtime?
======================== EDIT #1 ======================
C# script is already in Plugins folder:
and here is the errormessage:
===================== EDIT #2 ==============================
Here is the imported Standard Asset:
Now there's no problem with UnityStandardAssets.ImageEffects;
However I'm getting this error message:

Your code is missing the assembly import, therefore the compiler doesn't find the SunShaft class.
Place
using UnityStandardAssets.ImageEffects;
below
using System;
to import the assembly.

Related

Unity error CS0246: The type or namespace name 'UnityStandardAssets' could not be found

Even though there are surely a bunch of the same questions out there revealing the same exact topic as my problem, but I haven't found a suitable answer for me, therefore I do still have an issue.
Problem
I'm trying to code a game in Unity. The version I'm using is Unity 2021.3.15f1.
There, I have made a script (C#), which objective is to show a sequence message above the screen (subtitles for short). However, while making the script, I experienced the following error:
Assets\Scripts\Sequences\AOpening.cs(4,7): error CS0246: The type or namespace name 'UnityStandardAssets' could not be found (are you missing a using directive or an assembly reference?)
Here's my AOpening code, where the error came from:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityStandardAssets.Characters.FirstPerson;
using UnityEngine.UI;
public class AOpening : MonoBehaviour {
public GameObject ThePlayer;
public GameObject FadeScreenIn;
public GameObject TextBox;
void Start () {
ThePlayer.GetComponent<FirstPersonController> ().enabled = false;
StartCoroutine (ScenePlayer ());
}
IEnumerator ScenePlayer () {
yield return new WaitForSeconds (1.5f);
FadeScreenIn.SetActive (false);
TextBox.GetComponent<Text> ().text = "I need to get out of here.";
yield return new WaitForSeconds (2);
TextBox.GetComponent<Text> ().text = "";
ThePlayer.GetComponent<FirstPersonController> ().enabled = true;
}
}
What I tried?
Relaunching the Unity engine
Removing using UnityStandardAssets.Characters.FirstPerson; from the script
None of these helped me.
I'd be more than grateful if someone here would be able to help me resolve this problem. Many thanks and have a nice day!

UI Error and Method is marked as an override but no suitable method found to override

When I completed my whole game and then went to build it in the build settings, I came up with some of the errors which are general build errors and two errors of a script I haven't touch anywhere in my whole career. The script is a UI script that I didn't even touch or change in my whole game making process. And I also didn't found this error while I was working on the game or UI system. It suddenly pops up and now not letting me run the game.
Errors:
G:\Unity\2020.2.1f1\Editor\Data\Resources\PackageManager\BuiltInPackages\com.unity.ugui\Runtime\UI\Core\VertexModifiers\Outline.cs(14,30): error CS0115: 'Outline.ModifyMesh(VertexHelper)': no suitable method found to override
and
G:\Unity\2020.2.1f1\Editor\Data\Resources\PackageManager\BuiltInPackages\com.unity.ugui\Runtime\UI\Core\VertexModifiers\Outline.cs(9,28): error CS0246: The type or namespace name 'Shadow' could not be found (are you missing a using directive or an assembly reference?)
I have tried my best to find a solution and for the last few days I have been trying many things to solve it but I came up with nothing. But one thing to note I didn't found this error when I tried to fix it by downgrading my project to Unity 2019.4.18f1 but there I came up with some new errors which seems more complicated to me. Now I am asking for help here kind of being helpless after researching last week. Now I am also thinking of doing the project from scratch again. If you can help me then please because now only your help can save me from doing it from scratch for the next few weeks.
using System.Collections.Generic;
namespace UnityEngine.UI
{
[AddComponentMenu("UI/Effects/Outline", 15)]
/// <summary>
/// Adds an outline to a graphic using IVertexModifier.
/// </summary>
public class Outline : Shadow
{
protected Outline()
{ }
public override void ModifyMesh(VertexHelper vh)
{
if (!IsActive())
return;
var verts = ListPool<UIVertex>.Get();
vh.GetUIVertexStream(verts);
var neededCpacity = verts.Count * 5;
if (verts.Capacity < neededCpacity)
verts.Capacity = neededCpacity;
var start = 0;
var end = verts.Count;
ApplyShadowZeroAlloc(verts, effectColor, start, verts.Count, effectDistance.x, effectDistance.y);
start = end;
end = verts.Count;
ApplyShadowZeroAlloc(verts, effectColor, start, verts.Count, effectDistance.x, -effectDistance.y);
start = end;
end = verts.Count;
ApplyShadowZeroAlloc(verts, effectColor, start, verts.Count, -effectDistance.x, effectDistance.y);
start = end;
end = verts.Count;
ApplyShadowZeroAlloc(verts, effectColor, start, verts.Count, -effectDistance.x, -effectDistance.y);
vh.Clear();
vh.AddUIVertexTriangleStream(verts);
ListPool<UIVertex>.Release(verts);
}
}
}

Unity 4.6 C#: The type or namespace name `IOS' does not exist in the namespace `GooglePlayGames'

I have a game developed for iOS as well as android, Here is the code which suddenly started giving an error "Assets/GooglePlayGames/Platforms/PlayGamesClientFactory.cs(31,40): error CS0234: The type or namespace name IOS' does not exist in the namespaceGooglePlayGames'. Are you missing an assembly reference?
"
Here is the code:
using System;
using UnityEngine;
using UnityEngine.SocialPlatforms;
using GooglePlayGames.BasicApi;
namespace GooglePlayGames {
internal class PlayGamesClientFactory {
internal static IPlayGamesClient GetPlatformPlayGamesClient() {
if (Application.isEditor) {
return new GooglePlayGames.BasicApi.DummyClient();
}
#if UNITY_ANDROID
return new GooglePlayGames.Android.AndroidClient();
#elif UNITY_IPHONE
return new GooglePlayGames.IOS.IOSClient();
#else
return new GooglePlayGames.BasicApi.DummyClient();
#endif
}
}
}
Error is on the line:
return new GooglePlayGames.IOS.IOSClient();
The use of the platform dependent define "UNITY_IPHONE" is marked as Deprecated.
Unity documentation mentions UNITY_IOS as the new PLatform dependent define for the iOS platform.
http://docs.unity3d.com/Manual/PlatformDependentCompilation.html
The line of GooglePlayGames.IOS.IOSClient(); should be correct. ( not test in my code but the corresponding github archive shows the class in that place.)
Include using GooglePlayGames.IOS; at the top of your file.

Farseer ContactListener is not working

I'm using Farseer in my XNA project, but I have some trouble with the ContactListener. I created a class for my ContactListener but I always get these two error messages and I don't know how to fix the problems.
The type or namespace name 'ContactListener' could not be found (are you missing a using directive or an assembly reference?)
The type or namespace name 'ContactImpulse' could not be found (are you missing a using directive or an assembly reference?)
What is wrong with my ContactListener class?
class MyContactListener: ContactListener
{
void BeginContact(Contact contact)
{ /* handle begin event */ }
void EndContact(Contact contact)
{ /* handle end event */ }
void PreSolve(Contact contact, ref Manifold oldManifold)
{
Fixture fixtureA = contact.FixtureA;
Fixture fixtureB = contact.FixtureB;
if (fixtureB.CollisionCategories == Category.Cat10)
{
contact.Enabled = false;
}
}
void PostSolve(Contact contact, ref ContactImpulse impulse)
{ /* handle post-solve event */ }
}
Try this:
Open VS
Go to the Solution Explorer window
Search for a folder called References and right click it
Select Add Reference...
look for the Farseer assembly and add it
And try adding these in code:
using FarseerPhysics.Collision.Shapes;
using FarseerPhysics.Common;
using FarseerPhysics.Dynamics;
using FarseerPhysics.Dynamics.Contacts;
using FarseerPhysics.Factories;
using FarseerPhysics.TestBed.Framework;
using Microsoft.Xna.Framework;

The name 'myClassInstance' does not exist in the current context

Environment: c#.net VS 2010
Solution has the following two projects:
A dll with several tested methods I've added.
A test project
The only thing in the test project is a form with following code: (names changed for readability)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using DLL_PROJECT; //Yes I remembered to include the dll project
namespace DLL_PROJECT_Test
{
public partial class frmTest : Form
{
private Class_1 myClass_1; //this comes from the dll - no errors here
private Class_2 myClass_2 = new Class_2(); // no errors here either
public frmTest()
{
InitializeComponent();
//TransparencyKey = BackColor;
this.SetStyle(System.Windows.Forms.ControlStyles.SupportsTransparentBackColor, true);
this.BackColor = System.Drawing.Color.FromArgb(0, System.Drawing.Color.Black);
myDebouncer = new Debouncer(this);
this.SetDragging(true); //THIS EXTENSION COMES FROM THE DLL AND WORKS FINE
this.RoundCorners(40, 80); //AS DOES THIS ONE
myClass_2 = new Class_2();
myClass_2.HoldStartEvent += new Class_2EventHandler(myClass_2_HoldStartEvent);
myClass_2.DragStartEvent += new Class_2EventHandler(myClass_2_DragStartEvent);
}
private void myClass_2_DragStartEvent(Class_2 sender)
{
myClass_2("DragStart") += 1; //THE ONLY ERROR IS HERE AS FOLLOWS
//ERROR: "The name 'myClass_2' does not exist in the current context"
// - Yes, the DLL is included
// - Yes, the project is .Net 4 (not client profile)
// - Yes xxx WRONG xxx, this exact syntax has been tested before on an instance of
// this class, it's just a default parameter.
// xxx should be [] instead of () for the indexer in c#. #VB_Fails
}
void myClass_2_HoldStartEvent(Class_2 sender)
{
this.Close();
}
}
}
This code:
myClass_2("DragStart") += 1;
... is using myClass_2 as if it were either the name of a method or a delegate instance.
Did you actually mean to use the indexer? That would be:
myClass_2["DragStart"] += 1;
What does "DragStart" mean here? Is it actually a property name? Perhaps you want:
myClass_2.DragStart += 1;
I very much doubt that "this exact syntax has been tested before on an instance of this class".
Admittedly the error message doesn't make much sense in this case. I think it's actually more likely that you've got a typo in your real code - a typo which isn't propagated here because you've changed the names. If you could reproduce this in a short but complete program, it would make life a lot simpler.

Categories

Resources