Example #1
0
    //public void SetStars()
    //{
    //    if (Stars == null) return;
    //    for(int i=0; i<Stars.childCount;i++)
    //    {

    //        if( PlayerPrefs.HasKey($"{nameOfScene} {i} star collected"))
    //        {
    //            if(PlayerPrefs.GetInt($"{nameOfScene} {i} star collected")==1)
    //            {
    //                Destroy(Stars.GetChild(i).gameObject);
    //            }
    //        }
    //        else
    //        {
    //            PlayerPrefs.SetInt($"{nameOfScene} {i} star collected", 0);
    //        }
    //    }
    //}
    public void SetObstacles()
    {
        if (obstaclesList == null)
        {
            return;
        }
        //if (obstaclesList.ObstaclesOfScene == null) return;

        if (obstaclesList.ObstaclesOfScene.Item1 == nameOfScene)
        {
            for (int i = 0; i < Props.childCount; i++)
            {
                Transform PositionOfObstacle = Props.GetChild(i);
                string    name = obstaclesList.ObstaclesOfScene.Item2[i];
                foreach (ObstacleInventory obstacle in ListOfObstacles)
                {
                    if (obstacle.ObstacleName == name)
                    {
                        OpenPropsMenu installationPoint = PositionOfObstacle.gameObject.GetComponent <OpenPropsMenu>();
                        if (installationPoint.IsUsed())
                        {
                            Destroy(installationPoint.AttachedObstacle());
                        }
                        installationPoint.AttachMountedObstacle(Instantiate(obstacle.ObstaclePrefab, PositionOfObstacle.position + Vector3.forward, obstacle.ObstaclePrefab.transform.rotation, Obstacles), name);
                        installationPoint.Used();
                    }
                }
            }
        }
    }
    // Update is called once per frame
    public void FindObstacle(string name)
    {
        foreach (ObstacleInventory obstacle in ListOfObstacles)
        {
            if (obstacle.ObstacleName == name)
            {
                OpenPropsMenu installationPoint = PositionOfObstacles.gameObject.GetComponent <OpenPropsMenu>();
                if (installationPoint.IsUsed())
                {
                    Destroy(installationPoint.AttachedObstacle());
                }
                _obstaclesMenu.SetActive(false);

                installationPoint.AttachMountedObstacle(Instantiate(obstacle.ObstaclePrefab, PositionOfObstacles.position + Vector3.forward, obstacle.ObstaclePrefab.transform.rotation, Obstacles), name);
                installationPoint.Used();

                PositionOfObstacles.gameObject.GetComponent <Renderer>().material.color = new Color(0.5f, 0.5f, 0.5f, 0.5f);
            }
            else if (name == "Notype")
            {
                OpenPropsMenu installationPoint = PositionOfObstacles.gameObject.GetComponent <OpenPropsMenu>();
                if (installationPoint.IsUsed())
                {
                    Destroy(installationPoint.AttachedObstacle());
                }
                _obstaclesMenu.SetActive(false);
                installationPoint.AttachMountedObstacle(null, "Notype");
                installationPoint.UnUsed();
                PositionOfObstacles.gameObject.GetComponent <Renderer>().material.color = new Color(0.5f, 0.5f, 0.5f, 0.5f);
            }
        }
    }