< Summary

Class:LaunchProjectile
Assembly:Test
File(s):D:/--UnityProject/VR/VRExplorer_subjects/VR-Room/Assets/_Course Library/Scripts/Test/LaunchProjectile.cs
Covered lines:12
Uncovered lines:0
Coverable lines:12
Total lines:58
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)

D:/--UnityProject/VR/VRExplorer_subjects/VR-Room/Assets/_Course Library/Scripts/Test/LaunchProjectile.cs

#LineLine coverage
 1using BNG;
 2using System.Diagnostics.CodeAnalysis;
 3using UnityEngine;
 4using VRExplorer;
 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]
 14    public Grabbable Grabbable
 15    {
 16        get
 17        {
 18            var g = GetComponent<Grabbable>();
 19            if(g) return g;
 20            return gameObject.AddComponent<Grabbable>();
 21        }
 22    }
 23
 24    [ExcludeFromCodeCoverage] public void Triggerring() { }
 25
 26    [ExcludeFromCodeCoverage]
 27    public void Triggerred()
 28    {
 29        Fire();
 30    }
 31
 32    [ExcludeFromCodeCoverage] public void OnGrabbed() { }
 33
 34    [Tooltip("The projectile that's created")]
 535    public GameObject projectilePrefab = null;
 36
 37    [Tooltip("The point that the project is created")]
 538    public Transform startPoint = null;
 39
 40    [Tooltip("The speed at which the projectile is launched")]
 541    public float launchSpeed = 1.0f;
 42
 43    public void Fire()
 644    {
 645        GameObject newObject = Instantiate(projectilePrefab, startPoint.position, startPoint.rotation);
 46
 647        if(newObject.TryGetComponent(out Rigidbody rigidBody))
 648            ApplyForce(rigidBody);
 649    }
 50
 51    private void ApplyForce(Rigidbody rigidBody)
 652    {
 653        Vector3 force = startPoint.forward * launchSpeed;
 654        rigidBody.AddForce(force);
 655    }
 56
 57
 58}