Пример #1
0
    void SpawnGraveStone(GameObject block, GameObject dude)
    {
        int x = block.GetComponent <BlockController>().x;
        int z = block.GetComponent <BlockController>().z;

        int index = gridWidth * z + x;

        if (grid[index] == null)
        {
            return;
        }

        Destroy(grid[index]);

        grid[index] = (GameObject)Instantiate(graveStone);
        grid[index].SetActive(true);
        grid[index].transform.parent = gameObject.transform;

        // From ground
        float initialY = -3.0f;

        grid[index].transform.localPosition = GetLocalPosFromGridPos(x, z, initialY);

        GraveStoneController graveStoneController = grid[index].GetComponent <GraveStoneController>();

        graveStoneController.x        = x;
        graveStoneController.z        = z;
        graveStoneController.initialY = initialY;
        graveStoneController.dude     = dude; // For respawn, who died?
        graveStoneController.Spawn();
    }
Пример #2
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButton(0))
        {
            framesMouseDown++;

            RaycastHit hit;
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);

            if (Physics.Raycast(ray, out hit))
            {
                if (hit.collider != null)
                {
                    Debug.Log("Tag " + hit.collider.gameObject.tag);
                    if (hit.collider.gameObject.tag == "GraveStone")
                    {
                        if (Input.GetMouseButtonDown(0))
                        {
                            GraveStoneController graveStoneController = hit.collider.gameObject.GetComponent <GraveStoneController>();
                            if (graveStoneController != null)
                            {
                                HideMarker();
                                StartCoroutine(ExplodeGraveStoneAndRespawnDude(graveStoneController));
                                return;
                            }
                        }
                    }
                }
            }
            if (groundCollider.Raycast(ray, out hit, Mathf.Infinity))
            {
                Vector3 gridPos   = GetGridPositionFromWorldPos(hit.point);
                Vector3 markerPos = markerObject.transform.position;


                lastX = (int)gridPos.x;
                lastZ = (int)gridPos.z;


                ShowMarker(lastX, lastZ);
            }
        }
        else if (showingMarker)
        {
            HideMarker();


            if (framesMouseDown > frameLimitForCancel)
            {
                SpawnWall(lastX, lastZ, selectedDirection);
            }
            framesMouseDown = 0;
            lastX           = -1;
            lastZ           = -1;
        }
    }
Пример #3
0
    IEnumerator ExplodeGraveStoneAndRespawnDude(GraveStoneController graveStoneController)
    {
        explosionOnGoing = true;
        GameObject dude = graveStoneController.dude;

        graveStoneController.Explode();
        DestroyBlocksOnRadius(graveStoneController.x, graveStoneController.z, explosionRadius);
        yield return(new WaitForSeconds(2.0f));

        dude.GetComponent <DudeController>().Respawn();
        yield return(new WaitForSeconds(1.0f));

        explosionOnGoing = false;
    }