public void happyChecker(IntrovertScript receivedIntrovert)
    {
        happyIntroverts.Clear();
        unhappyIntroverts.Clear();

        foreach (IntrovertScript eachIntrovert in introverts)
        {
            if (eachIntrovert.amIHappy == true)
            {
                happyIntroverts.Add(eachIntrovert);
            }
            if (eachIntrovert.amIHappy == false)
            {
                unhappyIntroverts.Add(eachIntrovert);
            }

            if (ableToWin)
            {
                if (happyIntroverts.Count == introverts.Count && happyExtroverts.Count == extroverts.Count)
                {
                    Debug.Log("You win");
                    youWin.SetActive(true);
                    Next.SetActive(true);
                    Quit1.SetActive(true);
                    GameObject.Find("Main Camera").GetComponent <InputManager>().enabled = false;
                    myUnlocker = Camera.main.GetComponent <unlocker> ();
                    myUnlocker.LoadNextLevel();
                }
            }
        }
    }
示例#2
0
    //}
    // Use this for initialization


    void Start()
    {
        mySpriteRenderer = GetComponent <SpriteRenderer> ();

        myIntrovert = GetComponentInParent <IntrovertScript> ();
        if (numBreach > 3)
        {
            ChangeState(false);
        }
        else
        {
            ChangeState(true);
        }

        myExtrovert = GetComponentInParent <ExtrovertScript> ();
        if (numBreach > 4)
        {
            ChangeState(false);
        }
        else
        {
            ChangeState(true);
        }
    }
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PersonalSpaceScript : MonoBehaviour
{

	//SpriteRenderer socSprite = GetComponent<SpriteRenderer>();
	public Color unComfyColor = new Color();
	public Color comfyColor = new Color();

	public bool amIHappy;
	IntrovertScript myIntrovert;
	ExtrovertScript myExtrovert;

	private int numBreach = 0;

	public float changeSpeed = 10.0f;
	public float changeTime = 0.25f;
	SpriteRenderer mySpriteRenderer;
	int currentState = 2;

	void ChangeColor(Color newColor)
	{
		//SpriteRenderer persRender = GetComponent<SpriteRenderer>();
		//persRender.color = newColor;
	}


	void OnTriggerEnter2D(Collider2D collision)
	{
		RaycastHit2D myRaycast = Physics2D.Linecast (transform.position, collision.transform.position, myIntrovert.backgroundLayerMask);
		if (myRaycast.collider == null) {
			numBreach++;
			Debug.Log(numBreach);


			if (numBreach > 2)
			{
				ChangeState (false);
				//Debug.Log("Too Many In Personal Space!");
				//ChangeColor(unComfyColor);
				//amIHappy = false;
			}
		}
	}


	void OnTriggerExit2D(Collider2D collision)
	{
		RaycastHit2D myRaycast = Physics2D.Linecast (transform.position, collision.transform.position, myIntrovert.backgroundLayerMask);
		if (myRaycast.collider == null) {
			numBreach--;
			Debug.Log(numBreach);

			if (numBreach > 2) {
				ChangeState (false);
				//Debug.Log ("Too Many In Personal Space!");
				//ChangeColor (unComfyColor);
				//amIHappy = false;
			}  
			else { 
				ChangeState (true);
				//ChangeColor (comfyColor);
				//amIHappy = true;
			}
		}
	}

	void ChangeState(bool shouldIBeHappy) {
		if (shouldIBeHappy) {
			ChangeColor (comfyColor);
			amIHappy = true;
			HappyAnimation ();

		}  else {
			//Debug.Log("Too Many In Social Space!");
			ChangeColor(unComfyColor);
			amIHappy = false;
			UnhappyAnimation ();
		}
		myIntrovert.spaceStateChange ();
		//myExtrovert.spaceStateChange ();
	}

	// Use this for initialization


	void Start()
	{

		mySpriteRenderer = GetComponent<SpriteRenderer> ();

		myIntrovert = GetComponentInParent<IntrovertScript> ();
		if (numBreach > 0) {
			ChangeState (false);
		}  else {
			ChangeState (true);
		}

		myExtrovert = GetComponentInParent<ExtrovertScript> ();
		if (numBreach > 0 && numBreach < 2) {
			ChangeState (false);
		}  else {
			ChangeState (true);
		}


	}

	public void UnhappyAnimation() {
		CancelInvoke ("UnhappyAnimation");
		if (currentState != 0) {
			currentState = 0;
		}  else if (currentState == 0) {
			currentState = 1;
		}
		Invoke ("UnhappyAnimation", changeTime);
	}

	public void HappyAnimation() {
		CancelInvoke ("UnhappyAnimation");
		currentState = 2;
		mySpriteRenderer.color = comfyColor;
	}

	void Update()
	{
		if (currentState == 0) {
			mySpriteRenderer.color = Color.Lerp (mySpriteRenderer.color, unComfyColor, Time.deltaTime * changeSpeed);
		}  else if (currentState == 1) {
			mySpriteRenderer.color = Color.Lerp (mySpriteRenderer.color, comfyColor, Time.deltaTime * changeSpeed);
		}
	}

}