Esempio n. 1
0
    protected void SpawnNewObstacle(
        Mesh obstacleMesh,
        float passDistance,
        Material obstacleMaterial,
        Color materialColor)
    {
        // instantiating the mesh object and parenting it to the unit
        GameObject obstacleGO = new GameObject("Obstacle");

        //obstacleGO.transform.SetParent(transform);
        obstacleGO.transform.position = transform.position;
        obstacleGO.transform.Rotate(new Vector3(0f, 0f, Random.Range(0f, 359f)));

        MeshFilter        obstacleMeshFilter   = obstacleGO.AddComponent <MeshFilter>();
        MeshRenderer      obstacleMeshRenderer = obstacleGO.AddComponent <MeshRenderer>();
        MeshCollider      obstacleMeshCollider = obstacleGO.AddComponent <MeshCollider>();
        ObstacleBehaviour obstacleBehaviour    = obstacleGO.AddComponent <ObstacleBehaviour>();

        obstacleGO.layer = LayerMask.NameToLayer("Obstacles");
        obstacleBehaviour.Init(passDistance);



        //----------------
        // applying mesh and material
        obstacleMeshFilter.mesh = obstacleMesh;
        // obstacleMeshFilter.mesh.RecalculateNormals();
        obstacleMeshRenderer.material       = obstacleMaterial;
        obstacleMeshRenderer.material.color = materialColor;

        obstacleMeshCollider.sharedMesh = obstacleMeshFilter.mesh;
    }
Esempio n. 2
0
    public void SpawnObstacles()
    {
        obstacles = new List <ObstacleBehaviour>();
        for (int i = 0; i < App.gameManager.gridSize; i++)
        {
            ObstacleBehaviour oX = Instantiate(obstaclePrefab, new Vector3(10, 0.8f, -1.1f + i * 1.1f), Quaternion.identity, inGameParent);
            oX.Init(Vector3.right, true);
            obstacles.Add(oX);

            ObstacleBehaviour oZ = Instantiate(obstaclePrefab, new Vector3(-1.1f + i * 1.1f, 0.8f, 10), Quaternion.identity, inGameParent);
            oZ.Init(Vector3.forward, false);
            obstacles.Add(oZ);
        }
    }