< Summary

Class:LaunchProjectile
Assembly:Test
File(s):E:/Unity/Unity Project/VR-Room/Assets/_Course Library/Scripts/Test/LaunchProjectile.cs
Covered lines:12
Uncovered lines:0
Coverable lines:12
Total lines:63
Line coverage:100% (12 of 12)
Covered branches:0
Total branches:0
Covered methods:3
Total methods:3
Method coverage:100% (3 of 3)

Coverage History

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
LaunchProjectile()0%000100%
Fire()0%000100%
ApplyForce(...)0%000100%

File(s)

E:/Unity/Unity Project/VR-Room/Assets/_Course Library/Scripts/Test/LaunchProjectile.cs

#LineLine coverage
 1using BNG;
 2using System.Diagnostics.CodeAnalysis;
 3using UnityEngine;
 4using HenryLab;
 5
 6/// <summary>
 7/// Apply forward force to instantiated prefab
 8/// </summary>
 9public class LaunchProjectile : MonoBehaviour, ITriggerableEntity, IGrabbableEntity
 10{
 11    [ExcludeFromCodeCoverage] public float TriggeringTime => 1.5f;
 12    [ExcludeFromCodeCoverage] public string Name => Str.Gun;
 13    [ExcludeFromCodeCoverage] public Transform Destination => null;
 14
 15    [ExcludeFromCodeCoverage]
 16    public Grabbable Grabbable
 17    {
 18        get
 19        {
 20            var g = GetComponent<Grabbable>();
 21            if(g) return g;
 22            return gameObject.AddComponent<Grabbable>();
 23        }
 24    }
 25
 26    [ExcludeFromCodeCoverage] public void Triggerring() { }
 27
 28    [ExcludeFromCodeCoverage]
 29    public void Triggerred()
 30    {
 31        Fire();
 32    }
 33    [ExcludeFromCodeCoverage]
 34    public void OnReleased()
 35    {
 36    }
 37
 38    [ExcludeFromCodeCoverage] public void OnGrabbed() { }
 39
 40    [Tooltip("The projectile that's created")]
 241    public GameObject projectilePrefab = null;
 42
 43    [Tooltip("The point that the project is created")]
 244    public Transform startPoint = null;
 45
 46    [Tooltip("The speed at which the projectile is launched")]
 247    public float launchSpeed = 1.0f;
 48
 49    public void Fire()
 450    {
 451        GameObject newObject = Instantiate(projectilePrefab, startPoint.position, startPoint.rotation);
 52
 453        if(newObject.TryGetComponent(out Rigidbody rigidBody))
 454            ApplyForce(rigidBody);
 455    }
 56
 57    private void ApplyForce(Rigidbody rigidBody)
 458    {
 459        Vector3 force = startPoint.forward * launchSpeed;
 460        rigidBody.AddForce(force);
 461    }
 62
 63}