npc talk to nearby players
This commit is contained in:
15
Jump Game/Assets/Scripts/InteractionObject.cs
Normal file
15
Jump Game/Assets/Scripts/InteractionObject.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class InteractionObject : MonoBehaviour
|
||||
{
|
||||
public bool talks;
|
||||
public string message;
|
||||
public void Talk()
|
||||
{
|
||||
Debug.Log(message);
|
||||
}
|
||||
|
||||
|
||||
}
|
11
Jump Game/Assets/Scripts/InteractionObject.cs.meta
Normal file
11
Jump Game/Assets/Scripts/InteractionObject.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 416a1b62da70d7b478995f767ba96c11
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
34
Jump Game/Assets/Scripts/PlayerInteract.cs
Normal file
34
Jump Game/Assets/Scripts/PlayerInteract.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class PlayerInteract : MonoBehaviour
|
||||
{
|
||||
public GameObject currentInterObj = null;
|
||||
public InteractionObject currentInterObjScript = null;
|
||||
|
||||
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (Input.GetButtonDown ("Interact") && currentInterObj)
|
||||
{
|
||||
if (currentInterObjScript.talks)
|
||||
{
|
||||
currentInterObjScript.Talk();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
void OnTriggerEnter2D(Collider2D other)
|
||||
{
|
||||
if (other.CompareTag("interObject"))
|
||||
{
|
||||
Debug.Log(other.name);
|
||||
currentInterObj = other.gameObject;
|
||||
currentInterObjScript = currentInterObj.GetComponent <InteractionObject> ();
|
||||
}
|
||||
}
|
||||
}
|
11
Jump Game/Assets/Scripts/PlayerInteract.cs.meta
Normal file
11
Jump Game/Assets/Scripts/PlayerInteract.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1088a3f236f0e02439c2713c24252f61
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user