JetBrains Rider not catching ArgumentOutOfRange exception from Unity - unity3d

Is it just me ? Also Rider is very slow.
Tried with an empty Unity project with just a script and an empty list:
using System.Collections.Generic;
using UnityEngine;
public class TestException : MonoBehaviour
{
private List<int> emptyList= new List<int>();
void Start ()
{
emptyList[11] = 0;
}
}
JBR 2018.2.3
Unity 2018.2.8f1

Related

unity ads not showing up

i followed the official unity tutorial on how to put bannner ads on my game, i set everything up in the unity dashboard, and in the editor i see a rectangle that says the ad should be there, but when i build the game nothing shows up, here is my script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Advertisements;
public class bannerad : MonoBehaviour
{
bool testMode = false;
public string gameId = "******" (my game id is here i just dot want to share it);
// Start is called before the first frame update
IEnumerator Start()
{
Advertisement.Initialize(gameId, testMode);
while (!Advertisement.IsReady("Lost_Ad"))
{
yield return null;
}
Advertisement.Banner.SetPosition(BannerPosition.BOTTOM_CENTER);
Advertisement.Banner.Show("Lost_Ad");
}
}
anyone knows what is the solution?
Are you ever calling this function? If you just replaced the Start function with this IEnumerator it will not get called unless you call it.
private void Start()
{
Advertisement.Initialize(gameId, testMode);
StartCoroutine(StartAds());
}
private IEnumerator StartAds()
{
// your code here
}

Speech to text enabling in unity not working

I am using unity 2018.1.0f2 and windows 10. Below is the code.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Windows.Speech;
public class Dinovoice : MonoBehaviour {
KeywordRecognizer KeywordRecognizerObj;
void Start () {
string[] keywords_array={"Jump","Run"};
KeywordRecognizerObj= new KeywordRecognizer(keywords_array);
KeywordRecognizerObj.OnPhraseRecognized += KeywordRecognizer_OnPhraseRecognized;
KeywordRecognizerObj.Start();
Debug.Log("Started");
}
void Update() {
}
private void KeywordRecognizer_OnPhraseRecognized(PhraseRecognizedEventArgs args)
{
Debug.Log("Ended");
}
}
When I run from unity Started is getting printed.Ended is not getting printed at all when I speak.I am using unity with wikitude. I am adding this script to my prefab.Can you please help me out.Is there any setting I am missing?
Thanks

Unity UI doesn't set the interactability to true in script

I've had this problem before, and I can't stand it anymore. Why and how does this happen? I'm new to C# and I don't know what I'm doing wrong.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ButtonActivate : MonoBehaviour
{
bool Test;
Button ButtonHere;
void Update()
{
Test = true;
if (Test == true)
{
ButtonHere.interactable = true;
}
}
}
2 possible mistakes I can think of are:
Buttonhere is null or is referencing the wrong GameObject.
The script isn't attached to anything, try attaching it to something like the button itself or the 'Main Camera'.

Unity Networkserver.SpawnwithclientAuthroity doesn't work on host

I followed a Youtube tutorial https://www.youtube.com/watch?v=afz2An4X0vw on how to use Unity networking.
The point is to have an object with a network ID component spawn the player and in order to control the player we need to give the client spawning the player authority over that player.
However, having done exactly the same as in the video, whenever I host the game (with the unity Network HUD) the hasAuthority returns false instead of true on only the host.
It returns true on all the other clients (as it should).
To me it seems as if the hosting person doesn't see itself as a client but only the server, yet this doesn't happen in the video linked above.
How do I make the hosting player return true on hasAuthority as it refuses to do so with the code below?
The script on the object (spawned when the client connects):
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
public class ThePlayerScript : NetworkBehaviour
{
public GameObject abigail;
public GameObject abigailN;
void Start ()
{
if(isLocalPlayer == false)
{
return;
}
CmdSpawnPlayer();
}
void Update () { }
[Command]
void CmdSpawnPlayer()
{
abigailN = Instantiate(abigail);
NetworkServer.SpawnWithClientAuthority(abigailN, connectionToClient);
}
}
The code on the player that is spawned by the gameobject:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
public class Abigail : NetworkBehaviour
{
public GameObject mainCamera;
Vector3 myLocation;
Vector3 cameraView;
// Use this for initialization
void Start ()
{
if(hasAuthority == false)
{
Destroy(this);
return;
}
mainCamera = GameObject.Find("Main Camera");
}
}
(I removed the Update function in the Abigail class as it is irrelevant as it doesn't get executed.)
I found out that hasAuthority in this case will only return false in the Start() method. If you use it in the Update() method it will return true properly if you assign authority simply as you do in "ThePlayerScipt" with:
NetworkServer.SpawnWithClientAuthority(abigailN, connectionToClient);
Hope that helps :)

Picking up items in Unity

I have an Inventory system working and when I picked up an item it would go into it but I'm not sure what I changed because the item won't be picked up anymore. I'm trying to everything I can but now the only time I can add an item to my inventory is through the start function where it was initialized.
Here is the code attached to the player
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class BasePlayer : MonoBehaviour {
private List<BaseStat> _playerStats = new List<BaseStat> ();
private List<BaseItem> _playerInventory = new List<BaseItem>();
void Start () {
BaseItem _item = new BaseItem ();
BaseItem _weapon = new BaseItem ();
_weapon.ItemType = BaseItem.ItemTypes.WEAPON;
BaseItem _potion = new BaseItem();
_potion.WeaponType = BaseItem.WeaponTypes.BOW;
_potion.ItemType = BaseItem.ItemTypes.POTION;
_playerInventory.Add (_item);
_playerInventory.Add (_weapon);
_playerInventory.Add (_potion);
}
public List<BaseItem> ReturnPlayerInventory() {
return _playerInventory;
}
}
Here is the code attached to the item
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class Avalon : MonoBehaviour {
private List<BaseItem> playerInventory = new List<BaseItem>();
public GameObject Sword;
void Start () {
BasePlayer basePlayerScript = GameObject.FindGameObjectWithTag ("Player").GetComponent<BasePlayer> ();
playerInventory = basePlayerScript.ReturnPlayerInventory ();
}
void OnTriggerEnter2D(Collider2D col) {
if (col.CompareTag ("Player")) {
GreatSwordAvalon ();
Destroy (Sword.gameObject);
}
}
public void GreatSwordAvalon() {
BaseItem _avalon = new BaseItem ();
_avalon.ItemName = "GreatSword of Avalon";
_avalon.ItemDescription = "Strongest sword in the game";
_avalon.ItemType = BaseItem.ItemTypes.WEAPON;
_avalon.ItemValue = 999999;
_avalon.ItemStats.Add (new BaseStrength ());
_avalon.WeaponType = BaseItem.WeaponTypes.SWORD;
playerInventory.Add (_avalon);
}
}
Any help is greatly appreciated
I ended up solving the problem myself. In my Inventory Window script I have a function called AddItemsFromInventory that checks everything in the player inventory and adds it into the Inventory window.
The problem was that I had the call to the function in the start instead of the update so it constantly checks instead of just in the beginning.