private void Update() { if (Input.GetMouseButtonDown(1)) { var ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { if (MarkFx != null) { MarkFx.TargetPosition = hit.point; FxObjectInstancer.InstantiateOnCollisionFx(MarkFx, new CollisionPoint { Point = hit.point, Normal = hit.normal }); } if (MarkTargetMode == MarkMode.GameObject) { if (_markedObjects.Count >= MaxTargets) { return; } var gameObjectId = hit.transform.gameObject.GetInstanceID(); if (_markedObjects.ContainsKey(gameObjectId)) { return; } _markedObjects[gameObjectId] = hit.transform.gameObject; var materialAdded = hit.transform.gameObject.AddComponent <MaterialAdder>(); materialAdded.Material = _materialAdder.Material; materialAdded.LifeTime = _materialAdder.LifeTime; materialAdded.Run(); InvokeUtil.RunLater(this, () => { Destroy(materialAdded); _markedObjects.Remove(gameObjectId); }, LifeTime); } else { if (_markedPositions.Count >= MaxTargets) { return; } _markedPositions.Add(hit.point); InvokeUtil.RunLater(this, () => { _markedPositions.Remove(hit.point); }, LifeTime); } } } }
private void Awake() { var collisionProviders = GetComponents <ICollisionsProvider>(); foreach (var collisionsProvider in collisionProviders) { collisionsProvider.OnCollision += delegate(CollisionPoint collisionPoint) { if (_wasCollided) { return; } foreach (var fxObject in FxObjects) { fxObject.TargetPosition = collisionPoint.Point; FxObjectInstancer.InstantiateOnCollisionFx(fxObject, collisionPoint); } _wasCollided = true; }; } }