Hello
I have an object “AchievementManager” with “AchievementManager” Script and a DontDestroyOnLoad Script from a previous Scene that i need to reference in my current scene.
Here is my code
using UnityEngine;
using System.Collections;
public class HealthColidePlayer : MonoBehaviour {
GameObject AchievementManager1;
GameObject AchievementManager2;
void Start () {
AchievementManager1 = GameObject.Find("AchievementManager");
AchievementManager2 = AchievementManager1.GetComponent<AchievementManager>();
}
void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.tag == "Player")
{
AchievementManager2.AddProgressToAchievement("Amped Up", 1.0f);
//AchievementManager2.AddProgressToAchievement("Buzzing", 1.0f);
//AchievementManager2.AddProgressToAchievement("AllSheHasGot", 1.0f);
}
}
}
Please someone explain to me the right way of doing it the right way.
P.S. I know this kind of question has been answered many time, but the answers dont seem to be helping.
Thanks
Well, it doesn't give any errors. but its still not working. As far as the duplication you mentioned, i bypassed that by preloading the object in my first scene, so no problems there.
– XicerTry getting directly into the script: AchievementManager1.GetComponent< AchievementManager >().AddProgressToAchievement("Amped Up", 1.0f); Also, try putting a print or debug.log to see if your OnCollisionEnter is being called as expected.
– cj_coimbraHad to go to work. But i will try it as soon as i get home and reply here
– XicerWell you really helped me man. Your last comment did the trick. Thank you very much
– Xicer