- Home /
Score Points and Animation
For my game the player is supposed to fulfill different little tasks, like collecting 5 bags of gold, and when he collects these 5 items I want to give the player a star as reward and I want an animation of a star rotating around itself in the middle of the screen. The counter for the first items works so far, and the counter for the stars is displayed but doesn't add up when supposed to. Also, I created a star and the animation in 3DS max and imported that into Unity, I named the animation "Drehen", how can I get it to play when the player actually gets a star? This is my code atm, thanks for any help!
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class SammelnCounter : MonoBehaviour {
public Text sackZaehler;
private int zaehler;
public Text sternZaehler;
private int sternencounter;
Animator anim;
void Start () {
zaehler = 0;
sternencounter = 0;
SackZaehlText();
anim = GetComponent<Animator>();
}
void FixedUpdate() {
}
void OnTriggerEnter(Collider other) {
if (other.gameObject.CompareTag("Sack")) {
other.gameObject.SetActive (false);
zaehler = zaehler + 1;
SackZaehlText();
}
}
void SackZaehlText() {
if (zaehler >= 5) {
sternencounter = sternencounter + 1;
sackZaehler.text = "Quest abgeschlossen!";
Animation.Play("Drehen");
} else {
sackZaehler.text = "Goldsaecke: " + zaehler.ToString();
sternZaehler.text = "Sterne: " + sternencounter.ToString();
}
}
}
Where are you stuck exactly? you are struggling with playing the animations itself or the way it should be triggered? do you have any errors?
is the star in 3D? or is it just a sprite?
The score for the star is displayed on screen, but when I collect 5 goldbags the counter for the starts stays add 0, but it's supposed to go up by 1. And at the same time I want to trigger the animation, i don't exactly know how. It's a 3D Star created in 3DS $$anonymous$$ax, both the star and the animation were made in $$anonymous$$ax.
never dealt with animations, cant help you there but it looks like the sternencounter thing should be increasing. id say put a debug.log before the if statement in SackZaehlText() and one right after the if and before sternencounter = sternencounter + 1; if either one of those doesnt display, youll know exactly where its not working and can move on from there.
Your answer
Follow this Question
Related Questions
Animation Play On Bullet Shot 1 Answer
Problem with Collecting Stars 1 Answer
How do I make a double-tap system for dashing 7 Answers
Can the animation editor create local rotational data? 3 Answers