Example #1
0
    // The function to call when creating a clone to initialise everything
    public void Create(BaseMovement moveComponent, BaseCombat combatComponent, Vector3 startingPos, 
	                   float activeTime, GameObject target, GameObject projectilePrefab)
    {
        // Initialise the target
        m_Target = target;
        // Add a navmesh agent
        m_Agent = (NavMeshAgent) gameObject.AddComponent (Constants.NAV_AGENT);

        // Create a move component of the same type as the one passed
        System.Type movementType = moveComponent.GetType ();
        string moveType = movementType.ToString ();
        m_MovementComponent = (BaseMovement) gameObject.AddComponent (moveType);

        // Set the agent of that move component
        if (m_MovementComponent != null)
            m_MovementComponent.SetAgent (m_Agent);

        //Create a combat component of the same type as the one passed
        System.Type combatType = combatComponent.GetType ();
        string comType = combatType.ToString ();
        m_CombatComponent = (BaseCombat) gameObject.AddComponent (comType);

        // Initialise the projectile prefab
        if (m_CombatComponent != null)
            m_CombatComponent.SetProjectilePrefab (projectilePrefab);

        // Set the active timer
        m_ActiveTimer = activeTime;

        // move to the starting attack position
        if (m_MovementComponent != null)
            m_MovementComponent.Movement (startingPos);

        m_Health = 0.5f;
    }
Example #2
0
    public override void SetComponents(string[] components)
    {
        m_ComponentsObject = transform.FindChild(Constants.COMPONENTS_STRING).gameObject;

        m_CombatComponent    = m_ComponentsObject.GetComponent(components [0]) as BaseCombat;
        m_TargetingComponent = m_ComponentsObject.GetComponent(components [1]) as BaseTargeting;
        m_MovementComponent  = m_ComponentsObject.GetComponent(components [2]) as BaseMovement;
    }
    public override void SetComponents(string[] components)
    {
        m_ComponentsObject = transform.FindChild (Constants.COMPONENTS_STRING).gameObject;

        m_CombatComponent = m_ComponentsObject.GetComponent (components [0]) as BaseCombat;
        m_TargetingComponent = m_ComponentsObject.GetComponent (components [1]) as BaseTargeting;
        m_MovementComponent = m_ComponentsObject.GetComponent (components [2]) as BaseMovement;
    }
    // The function to call when creating a clone to initialise everything
    public void Create(BaseMovement moveComponent, BaseCombat combatComponent, Vector3 startingPos,
                       float activeTime, GameObject target, GameObject projectilePrefab)
    {
        // Initialise the target
        m_Target = target;
        // Add a navmesh agent
        m_Agent = (NavMeshAgent)gameObject.AddComponent(Constants.NAV_AGENT);

        // Create a move component of the same type as the one passed
        System.Type movementType = moveComponent.GetType();
        string      moveType     = movementType.ToString();

        m_MovementComponent = (BaseMovement)gameObject.AddComponent(moveType);

        // Set the agent of that move component
        if (m_MovementComponent != null)
        {
            m_MovementComponent.SetAgent(m_Agent);
        }

        //Create a combat component of the same type as the one passed
        System.Type combatType = combatComponent.GetType();
        string      comType    = combatType.ToString();

        m_CombatComponent = (BaseCombat)gameObject.AddComponent(comType);

        // Initialise the projectile prefab
        if (m_CombatComponent != null)
        {
            m_CombatComponent.SetProjectilePrefab(projectilePrefab);
        }

        // Set the active timer
        m_ActiveTimer = activeTime;

        // move to the starting attack position
        if (m_MovementComponent != null)
        {
            m_MovementComponent.Movement(startingPos);
        }

        m_Health = 0.5f;
    }