Beispiel #1
0
    // Start is called before the first frame update
    void Awake()
    {
        if (instance == null)
        {
            instance = this;
        }
        else if (instance != this)
        {
            Destroy(gameObject);
        }


        for (int ring = 1; ring <= numberOfRings; ring++)
        {
            GameObject currentRing    = new GameObject();
            float      circumference  = (float)(Mathf.PI * 2 * radius * ring);
            int        numberOfBlocks = Mathf.CeilToInt(circumference / lengthOfBlock);
            float      currentRadius  = (float)(radius * ring);
            for (int block = 1; block <= numberOfBlocks; block++)
            {
                if (Random.Range(0, 100) <= randomCapProb * 100)
                {
                    continue;
                }
                float   currentAngle = (360f / numberOfBlocks) * block;
                Vector3 position     = PointOnCircle(currentRadius + Random.Range(-offsetRadius, offsetRadius), currentAngle + Random.Range(-offsetRotation, offsetRotation));
                //Debug.Log("currentAngle: " + currentAngle + "  numberOfBlocks: " + numberOfBlocks + "  block: " + block + "  xPos: " + position.x + "  yPos: " + position.y);

                GameObject currentBlock = Instantiate(wallPrefab, position, Quaternion.Euler(0, 360 - currentAngle + Random.Range(-offsetAngle, offsetAngle), 0));
                currentBlock.transform.SetParent(currentRing.transform);
            }
            Rings.Add(currentRing);
        }
    }
Beispiel #2
0
 private void spawnPickup()
 {
     if (pickablePowerUps.Count >= 1)
     {
         GenerateRings rings         = RespawnPointsSource.GetComponent <GenerateRings>();
         Vector3       spawnLocation = rings.getSpawnLocation(randomRing: true);
         spawnLocation.y += 2;
         GameObject pickablePowerUp = pickablePowerUps[Random.Range(0, pickablePowerUps.Count)];
         Instantiate(pickablePowerUp, spawnLocation, Quaternion.Euler(0, 0, 0));
     }
 }
Beispiel #3
0
    void Respawn()
    {
        GenerateRings rings         = RespawnPointsSource.GetComponent <GenerateRings>();
        Vector3       spawnLocation = rings.getSpawnLocation(characterId);

        playerPoints = Mathf.FloorToInt(playerPoints * pointLossRate);
        controller.transform.position = spawnLocation;
        if (equipment != null)
        {
            Destroy(equipment);
            // equipment = null;
        }
    }
Beispiel #4
0
    void Respawn()
    {
        if (currentMove != null)
        {
            CompleteMove();
        }
        GenerateRings rings         = RespawnPointsSource.GetComponent <GenerateRings>();
        Vector3       spawnLocation = rings.getSpawnLocation(characterId);

        playerPoints = Mathf.FloorToInt(playerPoints * pointLossRate);
        controller.transform.position = spawnLocation;
        if (equipment != null)
        {
            Destroy(equipment);
            // equipment = null;
        }
        externalForce = new Vector3(0, 0, 0);
        inventory     = null;
    }
Beispiel #5
0
    // Start is called before the first frame update
    void Awake()
    {
        if (instance == null)
        {
            instance = this;
        }
        else if (instance != this)
        {
            Destroy(gameObject);
        }


        for (int ring = 1; ring <= numberOfRings; ring++)
        {
            GameObject        currentRing         = new GameObject();
            float             circumference       = (float)(Mathf.PI * 2 * radius * ring);
            int               numberOfBlocks      = Mathf.CeilToInt(circumference / lengthOfBlock);
            float             currentRadius       = (float)(radius * ring);
            List <GameObject> blocksOnCurrentRing = new List <GameObject>();
            Bounds?           lastBounds          = null;
            for (int block = 1; block <= numberOfBlocks; block++)
            {
                if (Random.Range(0, 100) <= randomCapProb * 100)
                {
                    continue;
                }
                float   currentAngle = (360f / numberOfBlocks) * block;
                Vector3 position     = PointOnCircle(currentRadius + Random.Range(-offsetRadius, offsetRadius), currentAngle + Random.Range(-offsetRotation, offsetRotation));
                //Debug.Log("currentAngle: " + currentAngle + "  numberOfBlocks: " + numberOfBlocks + "  block: " + block + "  xPos: " + position.x + "  yPos: " + position.y);

                GameObject currentBlock = Instantiate(wallPrefab, position, Quaternion.Euler(0, 360 - currentAngle + Random.Range(-offsetAngle, offsetAngle), 0));
                currentBlock.transform.SetParent(currentRing.transform);
                blocksOnCurrentRing.Add(currentBlock);
            }
            currentRing.AddComponent <NavMeshSurface>();
            currentRing.layer = 19;
            currentRing.GetComponent <NavMeshSurface>().collectObjects = CollectObjects.Children;
            currentRing.GetComponent <NavMeshSurface>().BuildNavMesh();

            foreach (GameObject block in blocksOnCurrentRing)
            {
                Bounds currentBlockBounds = block.GetComponent <BoxCollider>().bounds;
                currentBlockBounds.Expand(-1.5f);
                if (lastBounds != null)
                {
                    Bounds old = lastBounds ?? new Bounds();
                    if (!currentBlockBounds.Intersects(old))
                    {
                        Vector3 closestPointOld = old.ClosestPoint(block.transform.position);
                        closestPointOld.y += old.extents.y;
                        Vector3 closestPointNew = currentBlockBounds.ClosestPoint(closestPointOld);
                        closestPointNew.y += currentBlockBounds.extents.y;
                        if (maxLinkDistance >= Vector3.Distance(closestPointOld, closestPointNew))
                        {
                            NavMeshHit hit;

                            NavMeshLink newLink = block.AddComponent <NavMeshLink>();
                            NavMesh.SamplePosition(closestPointNew, out hit, maxLinkDistance, NavMesh.AllAreas);
                            newLink.startPoint = block.transform.InverseTransformPoint(hit.position);
                            NavMesh.SamplePosition(closestPointOld, out hit, maxLinkDistance, NavMesh.AllAreas);
                            newLink.endPoint      = block.transform.InverseTransformPoint(hit.position);
                            newLink.bidirectional = true;
                            newLink.autoUpdate    = true;
                        }
                    }
                }
                lastBounds = currentBlockBounds;
            }

            Rings.Add(currentRing);
        }
    }