Exemple #1
0
    public void Attack()
    {
        //Start posiiton for the particle effect to begin at
        Vector3 firePos = new Vector3(projectilePos.transform.position.x, projectilePos.transform.position.y, projectilePos.transform.position.z);

        //A new hit point that has the y value higher to be level with the character
        //Stops the projectile from hitting the ground
        Vector3 newHitPoint = player.transform.position;

        newHitPoint.y = firePos.y;

        //Instantiate the particle projectile at the fire position location.
        GameObject projectile = Instantiate(fireball, firePos, Quaternion.identity) as GameObject;

        Monster_Projectiles projSrc = projectile.GetComponent <Monster_Projectiles>();

        projSrc.SetDamage(attackDamage);

        //Rotate projectile to look at attack point
        projectile.transform.LookAt(newHitPoint);

        //Add a rigid body and add force to move it towards the location
        projectile.GetComponent <Rigidbody>().AddForce(projectile.transform.forward * 500);


        //Destroy the particle after a certain amount of time
        //Make sure it doesn't go on forever if it never hits an object
        Destroy(projectile, 7f);
    }
    public void InstantiateHelper(Vector3 firePosition, Vector3 attackPoint)
    {
        //Instantiate the particle projectile at the fire position location.
        GameObject projectile = Instantiate(skill, firePosition, Quaternion.identity) as GameObject;

        //Rotate projectile to look at attack point
        projectile.transform.LookAt(attackPoint);

        //Add a rigid body and add force to move it towards the location
        projectile.GetComponent <Rigidbody>().AddForce(projectile.transform.forward * 1000);

        Monster_Projectiles projScr = projectile.GetComponent <Monster_Projectiles>();

        projScr.SetDamage(damage);

        Destroy(projectile, 4f);
    }