Beispiel #1
0
    // Update is called once per frame
    void Update()
    {
        vrijemePucnja            -= Time.deltaTime;
        NeprijateljSpawningTimer -= Time.deltaTime;

        if (NeprijateljSpawningTimer <= 0f)
        {
            NeprijateljSpawningTimer = NeprijateljSpawningMirovanje;

            GameObject enemyObject = Instantiate(neprijateljPrefab);

            float randomAngle = Random.Range(0, Mathf.PI * 2);
            enemyObject.transform.position = new Vector3(gameCamera.transform.position.x + Mathf.Cos(randomAngle) * NeprijateljSpawningDistance, 0,
                                                         gameCamera.transform.position.z + Mathf.Sin(randomAngle) * NeprijateljSpawningDistance);

            Neprijatelj neprijatelj = enemyObject.GetComponent <Neprijatelj>();
            neprijatelj.direction = (gameCamera.transform.position - neprijatelj.transform.position).normalized;
            neprijatelj.transform.LookAt(Vector3.zero);
        }

        RaycastHit hit;

        if (Physics.Raycast(gameCamera.transform.position, gameCamera.transform.forward, out hit))
        {
            if (hit.transform.tag == "Neprijatelj" && vrijemePucnja <= 0f)
            {
                vrijemePucnja = vrijemeMirovanjaPucnja = 0;

                GameObject metakObject = Instantiate(metakPrefab);
                metakObject.transform.position = gameCamera.transform.position;

                Metak metak = metakObject.GetComponent <Metak> ();
                metak.direction = gameCamera.transform.forward;
            }
        }
    }
 // Use this for initialization
 void Start()
 {
     neprijatelj      = GetComponentInParent <Neprijatelj>(); // Different to way player's health bar finds player
     slikaTableZivota = GetComponent <RawImage>();
 }