Hi! I'm trying to learn about plugins in VAM. I don't have Unity background, but was able to google most of the things.
What I want to achieve:
1) Create CollisionTrigger atom
2) Listen to collision on this new atom
3) Display debug message if a collision happens
My code is below. The collider is created and I can select it in the scene. However, I can't trigger any action, so (3) doesn't work.
May be I miss some silly detail? I'm trying to trigger the collision by moving a person or a toy object. Am I doing something wrong?
Thank you for your help!
What I want to achieve:
1) Create CollisionTrigger atom
2) Listen to collision on this new atom
3) Display debug message if a collision happens
My code is below. The collider is created and I can select it in the scene. However, I can't trigger any action, so (3) doesn't work.
May be I miss some silly detail? I'm trying to trigger the collision by moving a person or a toy object. Am I doing something wrong?
Thank you for your help!
C#:
using System;
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using SimpleJSON;
namespace TieupNNJ {
public class ColliderTest: MVRScript {
public override void Init()
{
pluginLabelJSON.val = "Collider test";
StartCoroutine(CreateCollistionTrigger());
}
private IEnumerator CreateCollistionTrigger()
{
yield return SuperController.singleton.AddAtomByType("CollisionTrigger", "MyCollider");
try {
Atom createdCollider = SuperController.singleton.GetAtomByUid("MyCollider");
createdCollider.gameObject.AddComponent<CollisionTracker>();
SuperController.LogMessage("Collider created");
} catch (Exception ex) {
SuperController.LogError(ex.ToString());
}
}
public void OnDestroy()
{
}
public void OnUnLoad()
{
}
// Runs once when plugin loads - after Init()
protected void Start()
{
// show a message
SuperController.LogMessage(pluginLabelJSON.val + " Loaded");
}
// A Unity thing - runs every physics cycle
public void FixedUpdate()
{
// put code here
}
// Unity thing - runs every rendered frame
public void Update()
{
}
}
class CollisionTracker : MonoBehaviour
{
private void OnTriggerEnter(Collider other)
{
// This will be called when another collider enters the trigger
SuperController.LogMessage(other.name + " entered the trigger.");
}
private void OnTriggerStay(Collider other)
{
// This is called once per frame for every collider that stays inside the trigger
// Use with caution as it can be performance intensive if many objects are inside the trigger
}
private void OnTriggerExit(Collider other)
{
// This will be called when a collider exits the trigger
Debug.Log(other.name + " exited the trigger.");
}
}
}