- Home /
Why don't I get 20 poits in my trigger function?
using UnityEngine; using System.Collections; using UnityEngine.UI;
public class gameLeitung : MonoBehaviour {
Hey, I am beginner and i need help. I don't know what mistake i had written. I want get 20 points but it doesn't work. I can't access the other script but why? Sorry, i hope u understand my english my english is bad.
public int points; public int gesamtPunktzahl; public Text punkte; public Text perfect; public Text gesamtPKT; public bool fertig = false; public float timer = 60;
Ray ray;
RaycastHit hit;
public void Start ()
{
points = 0;
gesamtPunktzahl = PlayerPrefs.GetInt("Gesamtpunktzahl", gesamtPunktzahl);
}
public void FixedUpdate () {
punkteZeigen();
punkteAbgleich();
spielIstFertig();
if(fertig == false)
{
timer -= Time.deltaTime;
}
for(int i = 0; i < Input.touchCount; i++ )
{
if (Input.GetTouch(i).phase == TouchPhase.Began)
{
Ray ray = Camera.main.ScreenPointToRay(Input.GetTouch(0).position);
if (Physics.Raycast(ray, out hit))
{
if (hit.collider.gameObject.tag == "Gegner")
{
Destroy(hit.collider.gameObject);
punkteZufügen();
}
}
}
}
if (points < 0)
{
points = 0;
}
}
public void spielIstFertig()
{
if(timer < 0)
{
fertig = true;
finish();
timer = 5;
}
}
public void finish()
{
if(fertig == true)
{
gesamtPunktzahl = gesamtPunktzahl + points;
PlayerPrefs.SetInt("Gesamtpunktzahl", gesamtPunktzahl);
gesamtPKT.text = "gesamtPunktzahl" + gesamtPunktzahl;
}
}
public void punkteZufügen()
{
points++;
}
public void Punktabzug()
{
points--;
}
public void OnTriggerEnter(Collider col)
{
if (col.gameObject.tag == "Gegner")
{
Destroy(col.gameObject);
Punktabzug();
}
}
public void punkteZeigen()
{
punkte.text = "Punkte: " + points.ToString();
}
public void punkteAbgleich()
{
if (points == 50)
{
perfect.text = "PERFEKT";
}
}
}
using UnityEngine; using System.Collections;
public class touch : MonoBehaviour {
public GameObject TNT;
public GameObject whatToSpawnPrefab;
public GameObject whatToSpawnClone;
Ray ray;
RaycastHit hit;
// Use this for initialization
public void Start () {
}
// Update is called once per frame
public void FixedUpdate () {
if (Input.GetTouch(0).phase == TouchPhase.Began)
{
Ray ray = Camera.main.ScreenPointToRay(Input.GetTouch(0).position);
if (Physics.Raycast(ray, out hit))
{
if (hit.collider.gameObject.tag == "Gegner")
{
Destroy(hit.collider.gameObject);
}
if(hit.collider.gameObject.tag == "TNT")
{
whatToSpawnClone = Instantiate(whatToSpawnPrefab, TNT.transform.position, Quaternion.Euler(0, 0, 0)) as GameObject;
Destroy(hit.collider.gameObject);
GetComponent<gameLeitung>().points = GetComponent<gameLeitung>().points + 20;
}
Answer by CheetahSpeedLion · Jul 12, 2017 at 04:26 AM
Looks like if you hit a gameObject tagged with "TNT" you should be getting 20 points. What exact error are you getting when you try to access "gameLeitung"?
Areleli
it is strange. No error code is displayed. If I write debug.Log ("hiii") under the 20 points this is executed but not with the 20 points.
Is the gameLeitung component on the same object this script is in? Is the points variable public? Since you're adding points in a different script, it's probably an issue with that script and not this one.
Areleli
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Trigger Sound more than Once 0 Answers
Trigger AI character when certain condition is met 1 Answer
How To Stop Movement With RigidBody.AddForce 2 Answers
Multiple Cars not working 1 Answer