-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPickup.cs
More file actions
44 lines (34 loc) · 831 Bytes
/
Pickup.cs
File metadata and controls
44 lines (34 loc) · 831 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using System;
using Sandbox;
public sealed class Pickup : Component, Component.ITriggerListener
{
[Property] GameObject Body { get; set; }
[Property] public GameObject WeaponPrefab { get; set; }
Vector3 offset;
protected override void OnStart()
{
offset = Body.LocalPosition;
}
protected override void OnUpdate()
{
Body.LocalPosition = offset + Vector3.Up * 3f * MathF.Sin( Time.Now * 2f );
Body.LocalRotation = Rotation.FromYaw( Time.Now * 100f );
}
public void OnTriggerEnter( Collider other )
{
if ( !Networking.IsHost ) return;
if ( other.Components.GetInParentOrSelf<Player>() is Player player )
{
player.GiveWeapon( GameObject.Id );
GameObject.Destroy();
}
}
public void OnTriggerExit( Collider other )
{
}
[Rpc.Broadcast]
public void DestroyMe()
{
GameObject.Destroy();
}
}