Example #1
0
 void Start()
 {
     //cm = GetComponent<CharacterMovement>();
     rpi    = GetComponent <RayPlayerInput>();
     rm     = GetComponent <RayMovement>();
     diagUI = FindObjectOfType <DialogueUI>();
 }
Example #2
0
    GameObject SpawnEntity(Entity entity, Vector3 position = default(Vector3))
    {
        // Initiates default spawn position (-5y because floor is about -6y)
        Vector3 spawnPosition = new Vector3(0f, -5f, 0f);

        // Changes position if it is set in parameters
        if (position != default(Vector3))
        {
            spawnPosition = position;
        }

        // Creates the gameobject from prefab with character name
        GameObject go = (GameObject)Instantiate(characterPrefab, spawnPosition, Quaternion.identity);

        go.name = entity.character.characterName;

        // If conversation is set, gives it to the spawned character
        if (entity.character.VideConversation != null)
        {
            go.GetComponent <VIDE_Assign>().assignedDialogue = entity.character.VideConversation;
            go.GetComponent <VIDE_Assign>().assignedIndex    = entity.character.VideConversationIndex;
        }

        // If animator is set, gives it to the spawned character
        if (entity.character.animator != null)
        {
            go.GetComponentInChildren <Animator>().runtimeAnimatorController = entity.character.animator;
        }

        // If pose sprite is set, changes the sprite to that
        // Not probably needed
        //if (character.characterPoseSprite != null)
        //{
        //    Debug.Log(character.name + " had pose sprite.");
        //    Debug.Log("Changing sprite to " + character.characterPoseSprite.name);
        //    go.GetComponentInChildren<SpriteRenderer>().sprite = character.characterPoseSprite;
        //}

        // Gets components to memory for easy access
        RayNPC               rnpc = go.GetComponent <RayNPC>();
        RayPlayerInput       rpi  = go.GetComponent <RayPlayerInput>();
        CharacterInteraction ci   = go.GetComponent <CharacterInteraction>();

        // Checks if character is currently NPC
        if (entity.isNPC)
        {
            // Enables/sets NPC stuff and disables player stuff
            go.transform.SetParent(GameObject.FindGameObjectWithTag("NPC_Container").transform);
            go.tag       = "NPC";
            rnpc.enabled = true;
            rnpc.SetAIBehaviourActive(true);
            rpi.enabled = false;
            ci.enabled  = false;
        }
        else
        {
            // Enables/sets player stuff and disables NPC stuff
            go.transform.parent = FindObjectOfType <AdvancedHivemind>().transform;
            go.tag = "Player";
            rnpc.SetAIBehaviourActive(false);
            rnpc.enabled = false;
            rpi.enabled  = true;
            ci.enabled   = true;
        }

        //go.AddComponent<Entity>().CopyStats(entity);
        //allCharacters[allCharacters.IndexOf(entity)] = go.GetComponent<Entity>();
        //charactersOnLevel.Add(go.GetComponent<Entity>());

        //Debug.Log("Entity: " + go.GetComponent<Entity>().character.characterName);

        //if (go.GetComponent<Entity>().isInfected) infectedCharacters.Add(go.GetComponent<Entity>());

        //go.AddComponent<Entity>().character = entity.character;
        //Debug.Log(go.GetComponent<Entity>().character.characterName);

        Entity e = go.GetComponent <Entity>();

        //e.character = entity.character;
        CopyEntities(ref e, entity);
        Debug.Log(allCharacters[allCharacters.IndexOf(entity)]);

        allCharacters[allCharacters.IndexOf(entity)] = go.GetComponent <Entity>();
        charactersOnLevel.Add(go.GetComponent <Entity>());
        if (go.GetComponent <Entity>().isInfected)
        {
            infectedCharacters.Add(go.GetComponent <Entity>());
        }

        // Hides comment box
        go.transform.GetComponentInChildren <RandomComment>().transform.parent.gameObject.SetActive(false);

        return(go);
    }
Example #3
0
    /// <summary>
    /// Spawns a character based on information from Entity class.
    /// </summary>
    /// <param name="entity">Character to spawn.</param>
    /// <param name="position">Position to spawn the character to.</param>
    /// <returns>Returns the whole character gameobject.</returns>
    GameObject SpawnEntity(int indexOfEntity, Vector3 position = default(Vector3))
    {
        // If character's infection is in its final stage and no time is left, does not spawn this character
        if (allCharacters[indexOfEntity].currentStateOfInfection == CharacterEnums.InfectionState.Final && allCharacters[indexOfEntity].currentInfectionStageDuration <= 0)
        {
            Entity en = allCharacters[indexOfEntity];
            en.isAlive = false;
            return(null);
        }

        // Gets map's width and randomizes x position to be somewhere in the map
        float mapWidth = FindObjectOfType <BackgroundGenerator>().GetBackgroundWidth();
        float xPos     = UnityEngine.Random.Range(-mapWidth / 2, mapWidth / 2);

        // Initiates default spawn position with random x position and -5.9y, because floor is about -6y
        Vector3 spawnPosition = new Vector3(xPos, -5.9f, 0f);

        // Changes position if it is set in parameters
        if (position != default(Vector3))
        {
            spawnPosition = position;
        }

        // Creates the gameobject from prefab with character name
        GameObject go = (GameObject)Instantiate(characterPrefab, spawnPosition, Quaternion.identity);

        go.name = allCharacters[indexOfEntity].character.characterName;

        // If conversation is set, gives it to the spawned character
        if (allCharacters[indexOfEntity].character.VideConversation != null)
        {
            go.GetComponent <VIDE_Assign>().assignedDialogue = allCharacters[indexOfEntity].character.VideConversation;
            go.GetComponent <VIDE_Assign>().assignedIndex    = allCharacters[indexOfEntity].character.VideConversationIndex;
        }

        // If animator is set, gives it to the spawned character
        if (allCharacters[indexOfEntity].character.animator != null)
        {
            go.GetComponentInChildren <Animator>().runtimeAnimatorController = allCharacters[indexOfEntity].character.animator;
        }

        // If pose sprite is set, changes the sprite to that
        // Not probably needed
        //if (character.characterPoseSprite != null)
        //{
        //    go.GetComponentInChildren<SpriteRenderer>().sprite = character.characterPoseSprite;
        //}

        // Gets components to memory for easy access
        Entity               e    = go.GetComponent <Entity>();
        RayNPC               rnpc = go.GetComponent <RayNPC>();
        RayPlayerInput       rpi  = go.GetComponent <RayPlayerInput>();
        CharacterInteraction ci   = go.GetComponent <CharacterInteraction>();

        // Checks if character is currently NPC
        if (allCharacters[indexOfEntity].isNPC)
        {
            // Enables/sets NPC stuff and disables player stuff
            go.transform.SetParent(GameObject.FindGameObjectWithTag("NPC_Container").transform);
            go.tag       = "NPC";
            rnpc.enabled = true;
            rnpc.SetAIBehaviourActive(true);
            rpi.enabled = false;
            ci.enabled  = false;
        }
        else
        {
            // Enables/sets player stuff and disables NPC stuff
            go.transform.parent = FindObjectOfType <AdvancedHivemind>().transform;
            go.tag = "Player";
            rnpc.SetAIBehaviourActive(false);
            rnpc.enabled = false;
            rpi.enabled  = true;
            ci.enabled   = true;
            infectedCharacters.Add(go.GetComponent <Entity>());
            if (allCharacters[indexOfEntity].currentStateOfInfection == CharacterEnums.InfectionState.None)
            {
                allCharacters[indexOfEntity].currentStateOfInfection = CharacterEnums.InfectionState.State1;
            }
        }

        // Updates character's entity class
        CopyEntities(ref e, allCharacters[indexOfEntity]);

        // Adds the entity the lists of entities
        allCharacters[indexOfEntity] = go.GetComponent <Entity>();
        charactersOnLevel.Add(go.GetComponent <Entity>());

        // Hides comment box
        go.transform.GetComponentInChildren <RandomComment>().transform.parent.gameObject.SetActive(false);

        return(go);
    }