how to fix loading a scene in unity - visual-studio

The script is to move to the next scene when the "new game" button is pressed. The sound effect plays, but it does not go to the next scene and I get this error :ArgumentNullException: Value cannot be null.
Parameter name: source. I know you have to type null, but I don't know where.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SoundManagerScript : MonoBehaviour
{
public static AudioClip clikSound;
static AudioSource audioScr;
// Start is called before the first frame update
void Start()
{
clikSound = Resources.Load<AudioClip> ("clik");
audioScr = GetComponent<AudioSource> ();
}
// Update is called once per frame
void Update()
{
}
public static void PlaySound(string clip)
{
switch (clip)
{
case "clik":
audioScr.PlayOneShot(clikSound);
break;
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class MeinMenu : MonoBehaviour
{
static AudioSource audioScr;
public void NewGame()
{
SoundManagerScript.PlaySound("clik");
DontDestroyOnLoad(audioScr.gameObject);
SceneManager.LoadScene("level 1");
}
public void LoadGame()
{
SceneManager.LoadScene(PlayerPrefs.GetInt("SavedScene"));
}
}

Possible mistake: The scenes in the build are not there.
Go to File > Build Settings
Drag and drop your scenes in your Scenes folder into the Scenes in Build.

Related

I want to access a public method from one script to another in Unity. I have tried the below code

I am getting the below error while accessing ObjectPoolingManager.Instance.GetBullet(); in Player.cs from public GameObject GetBulltet () which is in ObjectPoolingManager.cs
Assets\SPF_Assets\Scripts\Game\Player.cs(4,7): error CS0138: A 'using namespace' directive can only be applied to namespaces; 'ObjectPoolingManager' is a type not a namespace. Consider a 'using static' directive instead
Player.cs Script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using ObjectPoolingManager; //Tried this, didnt work
public class Player : MonoBehaviour
{
public Camera playerCamera;
public GameObject bulletPrefab;
// Update is called once per frame
void Update() {
if(Input.GetMouseButtonDown(0)){
ObjectPoolingManager.Instance.GetBullet();
GameObject bulletObject = Instantiate (bulletPrefab);
bulletObject.transform.position = playerCamera.transform.position + playerCamera.transform.forward;
bulletObject.transform.forward = playerCamera.transform.forward;
}
}
}
ObjectPoolingManager.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ObjectPoolingManager : MonoBehaviour {
private static ObjectPoolingManager instance;
public static ObjectPoolingManager Instance { get { return instance; } }
// Start is called before the first frame update
void Awake () {
instance = this;
}
public GameObject GetBulltet () {
Debug.Log ("Hell0");
return null;
}
}
I re-read the code multiple times and finally realised your answer is right in your question already:
I am getting the below error while accessing
ObjectPoolingManager.Instance.GetBullet(); in Player.cs
from public GameObject GetBulltet () which is in ObjectPoolingManager.cs
I verified this in your code and you actually call a function ObjectPoolingManager.Instance.GetBullet() even though there is no such function but instead GetBulltet() which should have been GetBullet() instead.

How to disable Carousel Page scrolling in Android

Using a custom renderer one can disable the swiping gesture of an CarouselPage on iOS like so:
using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
[assembly: ExportRenderer(typeof(CarouselPage), typeof(CustomCarouselPageRenderer))]
namespace App.iOS
{
public class CustomCarouselPageRenderer : CarouselPageRenderer
{
protected override void OnElementChanged(VisualElementChangedEventArgs e)
{
base.OnElementChanged(e);
UIView view = this.NativeView;
UIScrollView scrollView = (UIKit.UIScrollView)view.Subviews[0];
scrollView.ScrollEnabled = false;
}
}
}
How to accomplish the same on Android?
using Android.Content;
using XamFormsApp.Droid.Renderers;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
[assembly: ExportRenderer(typeof(CarouselPage), typeof(CustomCarouselPageRenderer))]
namespace StixApp.Droid.Renderers
{
public class CustomCarouselPageRenderer : VisualElementRenderer<CarouselPage>
{
public CustomCarouselPageRenderer(Context context) : base(context)
{
}
protected override void OnElementChanged(ElementChangedEventArgs<CarouselPage> e)
{
base.OnElementChanged(e);
var view = this.RootView;
X
X
}
}
}
There appears to be no way to access Subviews in the same way. One can access Children like so
Android.Views.View view = (Android.Views.View)GetChildAt(i);
How to know which Child is ScrollView if any?
Using a loop to check for this, like so,
for (int i = 0; i < ChildCount; ++i)
{
Android.Views.View view = (Android.Views.View)GetChildAt(i);
if (view is ScrollView)
{
}
}
Yields the following: "The given expression is never of the provided (ScrollView) type"
So! How to disable CarouselPage swipe/scrolling as is done in iOS quite elegantly?
UPDATE: Please see sample solution.
A couple of things.
For Android the view you are looking for is not a ScrollView but a ViewPager.
This can be found under the index 0 with the GetChildAt method.
Also, why are you using VisualElementRenderer<CarouselPage> as the parent class of your CustomCarouselPageRenderer. Instead use the CarouselPageRenderer as you did with iOS.
One last thing is that on Android the Scroll of a ViewPager cannot be disabled. To get this behavior you can listen to the Touch event. Setting the Handled property of TouchEventArgs to true will prevent the scrolling from happening.
Your whole class would look something like:
[assembly: ExportRenderer(typeof(CarouselPage), typeof(CustomCarouselPageRenderer))]
namespace StixApp.Droid.Renderers
{
public class CustomCarouselPageRenderer : CarouselPageRenderer
{
private bool _canScroll = false;
public CustomCarouselPageRenderer(Context context) : base(context)
{
}
public CustomCarouselPageRenderer()
{
}
protected override void OnElementChanged(ElementChangedEventArgs<CarouselPage> e)
{
base.OnElementChanged(e);
if (this.ChildCount > 0 && this.GetChildAt(0) is ViewPager viewPager)
{
viewPager.Touch -= ViewPagerTouched;
viewPager.Touch += ViewPagerTouched;
}
}
private void ViewPagerTouched(object sender, TouchEventArgs e)
{
e.Handled = !_canScroll;
}
}
}
Just change the value of _canScroll to true to allow the scrolling.
Hope this helps.-
Overridden Methods in ViewPager class:
public class NonSwipeableViewPager : ViewPager
{
public override bool OnTouchEvent(MotionEvent e)
{
return false;
}
public override bool OnInterceptTouchEvent(MotionEvent ev)
{
return false;
}
public override bool ExecuteKeyEvent(KeyEvent ev)
{
return false;
}
}
Changes to CarouselPageRenderer:
In class declaration:
public class MyCarouselPageRenderer : VisualElementRenderer<CarouselPage>
{
NonSwipeableViewPager _viewPager;
}
In OnElementChanged:
protected override void OnElementChanged(ElementChangedEventArgs<CarouselPage> e)
{
_viewPager = new NonSwipeableViewPager(Context);
}
Note: CarouselPageAdapter, CarouselPageRenderer, MeasureSpecFactory, ObjectJavaBox, and PageContainer all had to be copied from the Xamarin.Forms github to enable a custom CarouselPageRenderer implementation. All of this is in the github sample but hopefully this spells it out more clearly for future visitors.
Note2: I would like to stress that the true behavior we were trying to achieve is probably best done with a NavigationPage as this allows us to easily pop and push any and all pages at any time without having to address the swipe issue. That being said, hopefully this solution serves to aid anyone who need this behavior on a CarouselPage.

ObservableCollection made of strings Not updating

Ok, so, I'm trying to link an ObservableCollection from my Android project to my Cross-Platform Project::
I've got this so far...this is in my Cross-platform app
ObservableCollection<String> NewRef = DependencyService.Get<ISlateBluetoothItems>().test().testThing;
NewRef.CollectionChanged += TestThing_CollectionChanged;
listView.ItemsSource = NewRef;
private void TestThing_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
listView.ItemsSource = DependencyService.Get<ISlateBluetoothItems>().test().testThing;
Console.WriteLine("working");
}
The line "working" is never printed even if I make changes to the ObservableCollection on the android portion of my app...
Here's the interface I'm using for the DependencyService:
using System.Collections.ObjectModel;
namespace ThoughtCastRewrite.BluetoothX
{
public interface ISlateBluetoothItems
{
BluetoothItems test();
}
}
Here's the class I use to expose the list:
namespace ThoughtCastRewrite.BluetoothX
{
public class BluetoothItems
{
public ObservableCollection<String> testThing;
public BluetoothItems()
{
testThing = new ObservableCollection<String>();
testThing.Add("wtf?");
}
public void AddThis()
{
testThing.Add("ok");
}
}
}
This is in the Android portion of my app, it implements the ISlateBluetoothItems interface
BluetoothItems bluetoothItems = new BluetoothItems();
then I call
bluetoothItems.AddThis();
but "ok" is not added to my list! I don't get the CollectionChanged event firing off! What's the deal guys? What's the deal?
You should assign your ObservableCollection as a source of your listview only once, not after each change. Changes to the collection will be automaticcly propagated to the listview.

Assert that a mocked (MOQ thus DynamicProxy) event has no handlers attached

This is quite straight forward(ish) to do is the event is 'real' as in now created by DynamicProxy, but I can't work anything out for a mocked event.
The best way to explain what I'm trying to achieve is with code, please see the comment lines in the test method:
using System;
using Moq;
using NUnit.Framework;
namespace MOQTest
{
[TestFixture]
public class EventsMoqTest
{
[Test]
public void DetachTest()
{
var hasEventMock = new Mock<IHasEvent>();
using (var observer = new Observer(hasEventMock.Object))
{
//Assert that hasEventMock.Object has handler attached
}
//Assert that hasEventMock.Object DOES NOT have handler attached
}
}
public interface IHasEvent
{
event EventHandler AnEvent;
}
public class Observer : IDisposable
{
private readonly IHasEvent _hasEvent;
private readonly EventHandler _hasEventOnAnEvent;
public Observer(IHasEvent hasEvent)
{
_hasEvent = hasEvent;
_hasEventOnAnEvent = _hasEvent_AnEvent;
_hasEvent.AnEvent += _hasEventOnAnEvent;
}
void _hasEvent_AnEvent(object sender, EventArgs e)
{}
public void Dispose()
{
_hasEvent.AnEvent -= _hasEventOnAnEvent;
}
}
}
Unfortunately, you can't. This isn't really a moq issue, but the way the C# event keyword works with delegates. See this SO answer for more information.

Cocoa: PhotoshopImage class and resize

Does anyone knows how i can resize the PhotoshopImage instance?
I don't us the UIImageView because i need to load a lot of images and the PhotoshopImage class handles it better.
Got a real shaky start for you! Photoshop has documentation on using javascript vbscript with photoshop dll's: http://www.adobe.com/devnet/photoshop/scripting.html. These same methods are exposed via COM to C# and I wonder if they're available to Objective-C (RedGate and the vs object browser can help if you dabble with it). Don't cringe at the C# code! The point is photoshop exposes dlls which can be worked with. C# ASP.NET exposes photoshop .dll's via COM. I'm new to objective-c and not a vet at C#! I got this code to work on my windows machine in C#. This code cranks up a web page and fires up my version of photoshop cs3 and goes thru my directory of files and creates an "Adobe image gallery". Good luck to you and post back what you find in objective-c...I think objective-c can run native C and I've seen some documentation of working with photoshop in native C...Shoot some code back either way...I'm a semi newbie so if this wasn't what you meant by Photoshop Image I apologize!
CDUB
PS these are all photoshop methods being exposed, nothing I made up...
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using GoogleTalkAPILib;
using ps = Photoshop;
using Photoshop;
namespace photoshop
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
try
{
Object ob= null;
//works!!!!!!
// co.Application.MakePDFPresentation(oaa,
"C:\Users\Photoshoptryrescl",ob);
//you can also use c# to run a javascript
// co.DoJavaScript("hey.js",e,d );
co.MakePhotoGallery(oab, "C:\\photoshopdump", ob);
}
catch (Exception ex)
{ Trace.Write(ex.Message.ToString()); }
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ps = Photoshop;
using Photoshop;
using Microsoft.Win32.SafeHandles;
using Microsoft.Win32;
using Microsoft;
namespace photoshop
{
public delegate void addBlur();
public class Class1 : ApplicationClass, ArtLayer, Document
{
public Class1()
{ }
public void addBlur()
{ }
public void addBlur1(string sa)
{ }
#region ArtLayer Members
public void AdjustBrightnessContrast(int Brightness, int Contrast)
{
throw new NotImplementedException();
}
public void AdjustColorBalance(object Shadows, object Midtones, object Highlights, object PreserveLuminosity)
{
throw new NotImplementedException();
}
public void AdjustCurves(object CurveShape)
{
throw new NotImplementedException();
}
public void AdjustLevels(int InputRangeStart, int InputRangeEnd, double InputRangeGamma, int OutputRangeStart, int OutputRangeEnd)
{
throw new NotImplementedException();
}
public bool AllLocked
{
get
{
throw new NotImplementedException();
}
set
{
throw new NotImplementedException();
}
}
public void ApplyAddNoise(double Amount, PsNoiseDistribution Distribution, bool Monochromatic)
{
throw new NotImplementedException();
}
public void ApplyAverage()
{
throw new NotImplementedException();
}
public void ApplyBlur()
{
// throw new NotImplementedException();
}
public void ApplyBlurMore()
{
throw new NotImplementedException();
}
//etc... these interfaces expose a ton of methods which can be explicity implemented
//this isn't them all

Resources