Exemplo n.º 1
0
        /// <summary>
        /// Moves the bullet forwards and handles collision detection.
        /// </summary>
        private void MoveBullet()
        {
            // Perform the raycast. Shoots a ray forwards of the bullet that covers all the distance
            // that it will cover in this frame. This guarantees a hit in all but the most extenuating
            // circumstances (against other extremely fast and small moving targets it may miss) and
            // works at practically any bullet speed.
            RaycastHit rayHit;
            Ray        velocityRay = new Ray(transform.position, velocity.normalized);
            bool       rayHasHit   = Physics.Raycast(velocityRay, out rayHit, velocity.magnitude * kVelocityMult * Time.deltaTime, hitMask);

            if (rayHasHit == true)
            {
                // Bullet hit something.
                // Put code here to damage the thing you hit using your components.
                CombatBehaviour combat = rayHit.transform.GetComponent <CombatBehaviour>();

                DestroyBullet(rayHit.point, true);
            }
            else
            {
                // Bullet didn't hit anything, continue moving.
                transform.Translate(velocity * Time.deltaTime, Space.World);

                // Account for bullet drop.
                velocity += Physics.gravity * gravityModifier * Time.deltaTime;

                // Align to velocity
                if (alignToVelocity == true)
                {
                    transform.rotation = Quaternion.LookRotation(velocity);
                }
            }
        }
Exemplo n.º 2
0
 private void Start()
 {
     combatBehaviour = GetComponentInParent <CombatBehaviour>();
     if (aiming == false)
     {
         aimPoint = transform.TransformPoint(Vector3.forward * 100.0f);
     }
 }
Exemplo n.º 3
0
    protected void Start()
    {
        tempTransform.enabled = false;

        combat = gameObject.GetComponent <CombatBehaviour>();
        self   = GetComponentsInChildren <Renderer>();

        OnStart();
    }
Exemplo n.º 4
0
        virtual protected void Start()
        {
            //selectUI = transform.Find("Highlight").gameObject;
            pathfinder   = GetComponent <PathFindingBehaviour>();
            combat       = GetComponent <CombatBehaviour>();
            animator     = GetComponentInChildren <Animator>();
            baseColor    = colorRenderer.material.color;
            groupManager = GameObject.FindGameObjectWithTag("Manager").GetComponentInChildren <GroupManager>();
            unitType     = unitStats.unitType;

            radius       = unitStats.radius;
            inputManager = FindObjectOfType <InputManager>();
        }
Exemplo n.º 5
0
    // Start is called before the first frame update
    void Start()
    {
        readyToShoot = true;
        StartCoroutine(RepeatShooting());
        if (combatBehaviours == null && GetComponentInParent <CombatBehaviour>() != null)
        {
            combatBehaviours = GetComponentInParent <CombatBehaviour>();

            enemyTags = GetComponentInParent <CombatBehaviour>().enemyTags;
        }

        if (shootingSfx == null)
        {
            shootingSfx = GetComponent <AudioSource>();
        }

        targeting = GetComponent <GunTargeting>();
    }
Exemplo n.º 6
0
 public void Construct(Bar bar, CombatBehaviour combatBehaviour)
 {
     _combatBehaviour = combatBehaviour;
     _bar             = bar;
 }
Exemplo n.º 7
0
 private void Start()
 {
     combatBehaviour = GetComponent <CombatBehaviour>();
     unitController  = GetComponentInParent <UnitController>();
     combatStat      = combatBehaviour.combatStats;
 }