Beispiel #1
0
    //OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
    override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        myCondannatiComponent = animator.GetComponentInParent <Condannati>();

        if (myCondannatiComponent.enableSangue)
        {
            hasSangue = myCondannatiComponent && myCondannatiComponent.sangue;

            if (hasSangue)
            {
                myCondannatiComponent.sangue.SetActive(true);
            }
        }

        Transform head = animator.transform.Find("Sphere001");

        if (head)
        {
            if (myCondannatiComponent.singleHeadPrefab)
            {
                OcchiEPelame thisOcchiEPelame = myCondannatiComponent.GetComponentInChildren <OcchiEPelame>();

                GameObject singleHeadInstance = Instantiate(myCondannatiComponent.singleHeadPrefab, thisOcchiEPelame.transform.position, thisOcchiEPelame.transform.rotation);
                GameObject newPelameVario     = Instantiate(thisOcchiEPelame.gameObject, singleHeadInstance.transform.GetChild(0).GetChild(0));

                if (myCondannatiComponent.enableSangue)
                {
                    singleHeadInstance.GetComponent <SingleHead>().sangueGameObject.SetActive(true);
                }

                singleHeadInstance.GetComponentInChildren <Rigidbody>().AddForce(((Camera.main.transform.position - singleHeadInstance.transform.position).normalized + Vector3.up) * 18, ForceMode.Impulse);
            }

            head.gameObject.SetActive(false);
        }

        animator.transform.GetComponentInChildren <OcchiEPelame>().gameObject.SetActive(false);
    }
    IEnumerator spawnPuppotto()
    {
        //vittima1 = Vittime[Random.Range(0, Vittime.Length)].GetComponent<Condannati>();
        do
        {
            int random = Random.Range(0, Vittime.Length);
            vittima1 = Vittime[random].GetComponent <Condannati>();
        }while (!vittima1.isAlive);
        if (vittima1 != null)
        {
            vittima1.gameObject.SetActive(true);

            //vittima1.gameObject.GetComponentInChildren<Outline>().enabled = true;
            vittima1.transform.position = spawnPoint1.position;
            inputManager.Condannato1    = vittima1.gameObject;
            vittima2 = vittima1.possibleMatches[Random.Range(0, vittima1.possibleMatches.Length)].GetComponent <Condannati>();
            do
            {
                int random = Random.Range(0, vittima1.possibleMatches.Length);
                vittima2 = vittima1.possibleMatches[random].GetComponent <Condannati>();
            }while (!vittima2.isAlive);

            if (vittima2 != null)
            {
                //vittima2.gameObject.GetComponentInChildren<Outline>().enabled = true;

                vittima2.gameObject.SetActive(true);
                vittima2.transform.position = spawnPoint2.position;
                inputManager.Condannato2    = vittima2.gameObject;
            }
        }

        moveSipario();


        yield return(null);
    }
    void Update()
    {
        if (selected != null)
        {
            //ceppo.enabled = true;
            //selected.GetComponentInChildren<Outline>().enabled = false;

            mypanel.SetActive(true);
        }
        else
        {
            //ceppo.enabled = false;
        }


        crowdScore.rectTransform.sizeDelta = new Vector2(40, currentCrowdScore * 2);
        kingScore.rectTransform.sizeDelta  = new Vector2(40, currentKingScore * 2);

        if (Input.GetMouseButtonDown(0) && GM.currentState == GameManager.State.GIOCO)
        {
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;

            if (Physics.Raycast(ray, out hit))
            {
                if (hit.transform.GetComponent <Condannati>())
                {
                    if (hit.transform.gameObject == Condannato1)
                    {
                        //Debug.Log("This is a Human1");
                        selected = Condannato1;
                        //Debug.Log(selected.name);
                        survivor             = Condannato2;
                        descriptionText.text = selected.GetComponent <Condannati>().description;
                        nome.text            = Condannato1.GetComponent <Condannati>().Nome;
                        crimine.text         = Condannato1.GetComponent <Condannati>().crimine;
                        circostanza.text     = Condannato1.GetComponent <Condannati>().circostanza;
                    }
                    else
                    {
                        mypanel.SetActive(true);
                        //Debug.Log("This is a Human");
                        selected = Condannato2;
                        //Debug.Log(selected.name);
                        survivor             = Condannato1;
                        descriptionText.text = selected.GetComponent <Condannati>().description;
                        nome.text            = Condannato2.GetComponent <Condannati>().Nome;
                        crimine.text         = Condannato2.GetComponent <Condannati>().crimine;
                        circostanza.text     = Condannato2.GetComponent <Condannati>().circostanza;
                    }

                    if (Mathf.Abs(selected.GetComponent <Condannati>().crowdScoreMod) < 6)
                    {
                        crowdSphere.rectTransform.sizeDelta = piccola;
                    }

                    if (5 < (int)Mathf.Abs(selected.GetComponent <Condannati>().crowdScoreMod) && (int)Mathf.Abs(selected.GetComponent <Condannati>().crowdScoreMod) < 11)
                    {
                        crowdSphere.rectTransform.sizeDelta = media;
                    }
                    if (10 < (int)Mathf.Abs(selected.GetComponent <Condannati>().crowdScoreMod) && (int)Mathf.Abs(selected.GetComponent <Condannati>().crowdScoreMod) < 16)
                    {
                        crowdSphere.rectTransform.sizeDelta = grande;
                    }

                    if ((int)Mathf.Abs(selected.GetComponent <Condannati>().kingScoreMod) < 6)
                    {
                        kingSphere.rectTransform.sizeDelta = piccola;
                    }

                    if (5 < (int)Mathf.Abs(selected.GetComponent <Condannati>().kingScoreMod) && (int)Mathf.Abs(selected.GetComponent <Condannati>().kingScoreMod) < 11)
                    {
                        kingSphere.rectTransform.sizeDelta = media;
                    }
                    if (10 < (int)Mathf.Abs(selected.GetComponent <Condannati>().kingScoreMod) && (int)Mathf.Abs(selected.GetComponent <Condannati>().kingScoreMod) < 16)
                    {
                        kingSphere.rectTransform.sizeDelta = grande;
                    }
                }

                else if (hit.transform.name == "Ceppo" && selected != null)

                {
                    if (selected.GetComponent <Condannati>().kingScoreMod > selected.GetComponent <Condannati>().crowdScoreMod)
                    {
                        FindObjectOfType <AudioManager>().Play("NobiliSoddisfatti");
                    }
                    else
                    {
                        FindObjectOfType <AudioManager>().Play("FollaSoddisfatta");
                    }


                    FindObjectOfType <AudioManager>().Stop("NobiliWaiting");
                    FindObjectOfType <AudioManager>().Play("BarFill");

                    GM.checkState(GameManager.State.ENDTURN);
                    survivor.GetComponent <Condannati>().Survive();

                    victim = selected;

                    Condannati victimCondamnedData = victim.GetComponent <Condannati>();

                    victimCondamnedData.PrepareToDie();

                    currentCrowdScore += victimCondamnedData.crowdScoreMod;
                    currentKingScore  += victimCondamnedData.kingScoreMod;

                    selected = null;
                    mypanel.SetActive(false);
                    //descriptionText.text = "";

                    if (victimCondamnedData.rank == Condannati.Rank.NOBILE)
                    {
                        currentNobiliUccisi += 1;
                        nobiliUccisi.text    = (currentNobiliUccisi) + " :";
                    }
                    else if (victimCondamnedData.rank == Condannati.Rank.POPOLANO)
                    {
                        currentPopolaniUccisi += 1;
                        popolaniUccisi.text    = ": " + (currentPopolaniUccisi);
                    }
                }

                else
                {
                    selected = null;
                    survivor = null;
                    //Debug.Log("This isn't a Player");
                    // descriptionText.text = "";
                    //nome.text = "";
                    //crimine.text = "";
                    //circostanza.text = "";
                    mypanel.SetActive(false);
                    kingSphere.rectTransform.sizeDelta  = new Vector2(0, 0);
                    crowdSphere.rectTransform.sizeDelta = new Vector2(0, 0);
                }
            }
        }
    }