Hi everyone I am using Unity 4 and purchased an asset thats supposed to work with Unity 4 and Android and iPhone but When I switch the platform to Android the Editor Throws 2 errors that I am not sure how to fix.
[/code]- Finished compile Library/ScriptAssemblies/Assembly-CSharp.dll
Assets/DogDays/RDR_Scripts/SimpleGestures.cs(50,43): error CS1501: No overload for method Add' takes
1’ arguments
(Filename: Assets/DogDays/RDR_Scripts/SimpleGestures.cs Line: 50)
Assets/DogDays/RDR_Scripts/SimpleGestures.cs(53,40): error CS1955: The member `SimpleGestures.touchDict’ cannot be used as method or delegate
(Filename: Assets/DogDays/RDR_Scripts/SimpleGestures.cs Line: 53)[/code]
Here is the code block that is throwing the error. Can anyone help Solve these 2 errors
#if UNITY_IPHONE || UNITY_ANDROID
var touches = Input.touches;
foreach(var touch in touches)
{
TouchStub stub;
if(!touchDict.ContainsKey(touch.fingerId))
{
stub = new TouchStub();
stub.Id = touch.fingerId;
stub.TimeHeldDown = 0f;
touchDict.Add(stub); // This is Line 50
}
else
stub = touchDict(touch.fingerId); // This is Line 53
stub.Position = touch.position;
switch(touch.phase)
{
case TouchPhase.Began:
if(OnFingerDown != null)
OnFingerDown(stub.Id, stub.Position);
break;
case TouchPhase.Ended:
case TouchPhase.Canceled:
if(OnFingerUp != null)
OnFingerUp(stub.Id, stub.Position, stub.TimeHeldDown);
touchDict.Remove(stub.Id);
break;
default:
stub.TimeHeldDown += Time.deltaTime;
break;
}
}
Is the definition for touchDict same on both platforms?
It look like it is the the same for all platforms here is the beginning of the code to to and including the block I showed earlier.
//-----------------------------------------------------------------
// Copyright 2013 Cats in the Sky, Ltd.
// All rights reserved
//-----------------------------------------------------------------
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
/// <summary>
/// A simple class to control touches and mouses as if they were the same thing.
/// </summary>
public class SimpleGestures : MonoBehaviour
{
#if UNITY_FLASH
public static List<GameObject> OnFingerDownList = new List<GameObject>();
public static List<GameObject> OnFingerUpList = new List<GameObject>();
#else
public static event OnSGFingerDown OnFingerDown;
public static event OnSGFingerUp OnFingerUp;
#endif
public static SimpleGestures Instance {get; private set;}
Dictionary<int, TouchStub> touchDict;
void Awake()
{
if(Instance != null)
{
Destroy(this.gameObject);
return;
}
touchDict = new Dictionary<int, TouchStub>();
DontDestroyOnLoad(this.gameObject);
Instance = this;
}
void Update()
{
#if UNITY_IPHONE || UNITY_ANDROID
var touches = Input.touches;
foreach(var touch in touches)
{
TouchStub stub;
if(!touchDict.ContainsKey(touch.fingerId))
{
stub = new TouchStub();
stub.Id = touch.fingerId;
stub.TimeHeldDown = 0f;
touchDict.Add(stub);
}
else
stub = touchDict(touch.fingerId);
stub.Position = touch.position;
switch(touch.phase)
{
case TouchPhase.Began:
if(OnFingerDown != null)
OnFingerDown(stub.Id, stub.Position);
break;
case TouchPhase.Ended:
case TouchPhase.Canceled:
if(OnFingerUp != null)
OnFingerUp(stub.Id, stub.Position, stub.TimeHeldDown);
touchDict.Remove(stub.Id);
break;
default:
stub.TimeHeldDown += Time.deltaTime;
break;
}
}
Thing is, that default C# dictionary takes two parameters for add
that is why I cannot see touchDict.Add(stub); working in that case. I can only assume it should be something like
if(!touchDict.ContainsKey(touch.fingerId))
{
stub = new TouchStub();
stub.Id = touch.fingerId;
stub.TimeHeldDown = 0f;
touchDict.Add(touch.fingerId, stub);
}
else
stub = touchDict[touch.fingerId];
genju
May 18, 2015, 3:30am
5