Skip to content

Commit 4b04491

Browse files
committed
Much more better :)
1 parent 1377635 commit 4b04491

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

ClickableCharacter.cs

+10-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using UnityEngine;
55
using UnityEngine.Events;
66
using System;
7+
using System.Linq;
78

89
namespace Fungus
910
{
@@ -120,6 +121,7 @@ public class ClickableCharacter : Command
120121

121122
[Tooltip("List of methods to call. Supports methods with one string parameter.")]
122123
[SerializeField] protected StringEvent stringEvent2 = new StringEvent();
124+
protected string myGoGo = "";
123125
protected Stage stage;
124126
protected virtual void DoInvoke()
125127
{
@@ -179,9 +181,10 @@ protected void CastRay()
179181
{
180182
Ray ray = mainCam.ScreenPointToRay(Input.mousePosition);
181183
RaycastHit2D hit = Physics2D.Raycast (ray.origin, ray.direction, Mathf.Infinity);
184+
182185
if (hit)
183186
{
184-
if(hit.collider.gameObject.name == character.name)
187+
if(hit.collider.gameObject.name == myGoGo)
185188
{
186189
if(enableDebugLog)
187190
{
@@ -191,11 +194,11 @@ protected void CastRay()
191194
//Invoke starts here!
192195
if (Mathf.Approximately(delay, 0f))
193196
{
194-
DoInvoke();
197+
this.DoInvoke();
195198
}
196199
else
197200
{
198-
Invoke("DoInvoke", delay);
201+
this.Invoke("DoInvoke", delay);
199202
}
200203
}
201204
}
@@ -240,14 +243,16 @@ protected void UpdateColliderPosition()
240243
241244
}
242245
*/
246+
private static int indexNum = 0;
243247
protected void AddCollider()
244248
{
245249
if(character != null && mainCam != null)
246250
{
247251
BoxCollider2D boxy;
248252
float rectX = character.State.portraitImage.rectTransform.sizeDelta.x;
249253
float rectY = character.State.portraitImage.rectTransform.sizeDelta.y;
250-
GameObject myGO = new GameObject(character.name);
254+
GameObject myGO = new GameObject(character.name + "_" + indexNum++);
255+
myGoGo = myGO.name;
251256
myGO.AddComponent<BoxCollider2D>();
252257
boxy = myGO.GetComponent<BoxCollider2D>();
253258
boxy.transform.SetParent(character.transform, false);
@@ -349,6 +354,7 @@ public override string GetSummary()
349354
}
350355
public override void OnEnter()
351356
{
357+
352358

353359
//Force 1st frame update
354360
Canvas.ForceUpdateCanvases();

0 commit comments

Comments
 (0)