```csharp
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class BallHandler : MonoBehaviour
{
[SerializeField] GameObject resBall;
[SerializeField] float detachDelay;
[SerializeField] float ResPawnDelay;
[SerializeField] Rigidbody2D pivot;
[SerializeField] Rigidbody2D Currentrb;
[SerializeField] SpringJoint2D currentJoint;
[SerializeField] float DelayedDUration;
Camera mainCam;
bool IsDrowning;
void Start()
{
mainCam = Camera.main;
SpawnNewBall();
}
void Update()
{
if(Currentrb == null) { return; }
if (!Touchscreen.current.primaryTouch.press.isPressed)
{
if(IsDrowning)
{
Launchball();
}
IsDrowning = false;
return;
}
IsDrowning = true;
Currentrb.isKinematic = true;
Vector2 TouchPos = Touchscreen.current.primaryTouch.position.ReadValue();
Vector3 worldPos = mainCam.ScreenToWorldPoint(TouchPos);
Currentrb.position = worldPos;
}
void SpawnNewBall()
{
GameObject balls = Instantiate(resBall, pivot.position, Quaternion.identity);
Currentrb = balls.GetComponent<Rigidbody2D>();
currentJoint = balls.GetComponent<SpringJoint2D>();
currentJoint.connectedBody = pivot;
}
void Launchball()
{
Currentrb.isKinematic = false;
Currentrb = null;
Invoke(nameof(DetachBall), DelayedDUration);
}
void DetachBall()
{
currentJoint.enabled = false;
currentJoint = null;
Invoke(nameof(SpawnNewBall), ResPawnDelay);
}
}
This is the script, during run time it works perfectly but when I build and run to export it over to my mobile, it gives out this problem! pls help me.
Like this
~~~csharp
ArgumentException: An item with the same key has already been added. Key: UnityEditor.Scripting.ScriptCompilation.ScriptAssembly
System.Collections.Generic.Dictionary`2[TKey,TValue].TryInsert (TKey key, TValue value, System.Collections.Generic.InsertionBehavior behavior) (at <eae584ce26bc40229c1b1aa476bfa589>:0)
System.Collections.Generic.Dictionary`2[TKey,TValue].Add (TKey key, TValue value) (at <eae584ce26bc40229c1b1aa476bfa589>:0)
~~~
pls advice
The 2D forums are not for general scripting issues, those should be posted on the Scripting forum. Also, you posted the error using code-tags but didn’t post the code using code-tags correctly so it’s harder to read.
You don’t say where the error comes from and there’s no direct use of dictionary above so no indication why you know it’s this script.
I’ll move your post to the scripting forum but I would suggest posting information such as which call the error comes from or what makes you suspect it’s the code you posted in the very least. Also, state if you want to know what the error means and what debugging you’ve done. Have you attached a debugger etc?