I just started integrating the 2D toolkit into a little demo I’ve been working on. I’ve been doing everything in JavaScript but the 2DToolkit stuff all seems to be in C#. The scenario is I have a Hero(JS) who detects collision with coins, and I need to increment the score counter (C#). I’ve tried somethings and haven’t been able to make it work. Here’s my HUD script:
using UnityEngine;
using System.Collections;
public class TextMeshExample : MonoBehaviour {
tk2dTextMesh textMesh;
int score = 0;
// Use this for initialization
void Start () {
textMesh = GetComponent<tk2dTextMesh>();
}
// Update is called once per frame
void Update () {
//replace with something like textMesh.text = "SCORE: " HeroController.coinCount
if (Input.GetKey(KeyCode.Q))
{
score++;
textMesh.text = "SCORE: " + score.ToString();
// This is important, your changes will not be updated until you call Commit()
// This is so you can change multiple parameters without reconstructing
// the mesh repeatedly
textMesh.Commit();
}
}
}
and here’s part of my hero script:
function OnCollisionEnter(collision : Collision) {
if(collision.gameObject.name == "WaterBarrier") // If A collides with B
{
if (collision.relativeVelocity.magnitude > outOfWaterThreshold/100)
{
//Physics.gravity = Vector3(0, -1.5, 0);
//transform.position = Vector3(-0.6948604, .5, 3.701174);
print("We just hit the water level... Hard!!!");
//Physics.gravity = Vector3(0, 3, 0);
//transform.position = Vector3(-0.6948604, -.5, 3.701174);
}
}
//If we hit a coin increment the count and destroy it
if(collision.gameObject.name == "Coin" || collision.gameObject.name == "SilverCoin")
{
transform.position = Vector3(transform.position.x, transform.position.y, 3);
Destroy(collision.gameObject);
if(collision.gameObject.name == "Coin")
{
coinCount = coinCount+1;
}
else if(collision.gameObject.name == "SilverCoin")
{
coinCount = coinCount+2;
}
}
//If we hit a hazard increment the count and restart the level
if(collision.gameObject.name == "Hazard")
{
Application.LoadLevel ("ProofOfConcept");
hazardCount = hazardCount+1;
}
}
I’m trying my best, so if somebody could give me some insight I’d really appreciate it! Thanks so much!
Amen to that
– _invalidusername