예제 #1
0
    // Store initial position
    protected void Start()
    {
        lineRenderer = GetComponent <LineRenderer>();
        creationTime = Time.time;

        // Store shooter's old layermask
        OldLayer oldLayer = shooter.AddComponent <OldLayer>();

        oldLayer.oldlayer = shooter.layer;
        oldLayer.ChangeObjectLayermask(emptyLayer);

        // Raycast to check hit
        RaycastHit hitInfo;

        if (Physics.Raycast(transform.position, direction, out hitInfo, 1000.0f, layersToHit))
        {
            distance = hitInfo.distance;

            CharacterBase character = hitInfo.collider.gameObject.GetComponent <CharacterBase>();

            // If this is a character
            if (character != null)
            {
                // Do damage
                character.Health -= damage * damageMultiplier;
                if (character.Health < 0)
                {
                    character.Health = 0;
                }
                character.DamageTaken();
            }
            // If this is a wall
            else
            {
                Vector3 hitPoint = hitInfo.point;

                // Sink hitpoint into wall a tiny bit
                hitPoint -= hitInfo.normal * 0.001f;

                ((LevelGen)GameObject.FindObjectOfType(typeof(LevelGen))).BreakWall(hitPoint);
            }
        }

        // Restore shooter's layermask
        oldLayer.RestoreObjectLayer();
        Destroy(oldLayer);
    }