void RaycastPlayer() { Vector3 forward = transform.TransformDirection(Vector3.forward) * RayDistance; Debug.DrawRay(transform.position, forward, Color.green); if (Physics.Raycast(transform.position, (forward), out hit)) { theDistance = hit.distance; //print(theDistance + " " + hit.collider.gameObject.name); //เปลียนหน้าดิน if (hit.collider.tag.Equals("Wood")) { TargetHit target = hit.transform.GetComponent <TargetHit>(); Destruction swapTarget = hit.transform.GetComponent <Destruction>(); if (swapTarget != null) { swapTarget.SwapObject(); target.TakeDamage(damage); } //Instantiate(destroyedVersion, transform.position, transform.rotation); } } }
// Start is called before the first frame update void Start() { down = false; movingDown = false; movingUp = false; time = 0; changeInRotation = Vector3.forward; hit = TargetArea.GetComponent <TargetHit>(); }
public void OnBodyEntered(Node body) { TargetHit?.Invoke(new BulletHitInfo { WorldCoords = _worldCoords, Building = body as IBuilding }); _worldCoords = Vector3.Zero; QueueFree(); }
protected override void Update(GameTime time) { base.Update(time); if (!_initialized) { _initialized = true; _startTime = time.TotalGameTime; } float percent = (float)(_elapsedTime.TotalMilliseconds / _duration.TotalMilliseconds); if (percent > 0.99f) { Active = false; _tcs.SetResult(true); TargetHit?.Invoke(); } var offset = new Vector2(16, 16); _sourceWorld = Camera2D.Instance.HexToPixel(_source) + offset; _dstWorld = Camera2D.Instance.HexToPixel(_destination) + offset; _directionWorld = _dstWorld - _sourceWorld; Vector2 normDir = _directionWorld; normDir.Normalize(); var acos = Vector2.Dot(new Vector2(1, 0), normDir); double flip = 1; if (normDir.Y < 0) { flip = -1; } Rotation = (float)(flip * Math.Acos(acos)); Position = _sourceWorld + _directionWorld * percent + offset; _elapsedTime = time.TotalGameTime - _startTime; }
void RaycastPlayer() { Vector3 forward = transform.TransformDirection(Vector3.forward) * RayDistance; Debug.DrawRay(transform.position, forward, Color.green); if (Physics.Raycast(transform.position, (forward), out hit)) { theDistance = hit.distance; //print(theDistance + " " + hit.collider.gameObject.name); //ทำลายสิ่งของ TargetHit target = hit.transform.GetComponent <TargetHit>(); if (target != null) { target.TakeDamage(damage); } } }
public void Visit(TargetHit hit, Vector3 pos, GameObject inst) { SpawnObject(pos, inst); }