protected override void Start(SystemRegistry registry) { _input = registry.GetSystem <InputSystem>(); _ballCollider = GameObject.GetComponent <SphereCollider>(); int magnetTrackerLayer = registry.GetSystem <PhysicsSystem>().GetLayerByName("MagnetDetector"); _magnetTrackingZone = ObjectTrackingZone.Create(GameObject.Transform, Radius, "CrazyCore.Magnet", magnetTrackerLayer); _zoneSphereCollider = _magnetTrackingZone.GameObject.GetComponent <SphereCollider>(); AssetSystem assetSystem = registry.GetSystem <AssetSystem>(); _magnetParticleGo = assetSystem.Database.LoadAsset <SerializedPrefab>("Prefabs/MagnetParticles.prefab", false) .Instantiate(registry.GetSystem <GameObjectQuerySystem>()); _magnetParticles = _magnetParticleGo.GetComponent <ParticleSystem>(); _magnetParticleGo.Transform.Parent = Transform; _magnetParticleGo.Transform.LocalPosition = Vector3.Zero; }
public static ObjectTrackingZone Create(Transform parent, float radius, string markerTypeName, int layer) { GameObject tracker = new GameObject(markerTypeName + "_Tracker"); SphereCollider sphereCollider = new SphereCollider(radius); sphereCollider.IsTrigger = true; sphereCollider.IsAffectedByGravity = false; sphereCollider.Mass = 0f; sphereCollider.Layer = layer; tracker.AddComponent(sphereCollider); ObjectTrackingZone zone = new ObjectTrackingZone(); zone.ComponentMarkerTypeName = markerTypeName; tracker.AddComponent(zone); tracker.AddComponent(new TransformFollow() { Target = parent }); return(zone); }