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;
}