예제 #1
0
    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);
            }
        }
    }
예제 #2
0
 // 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>();
 }
예제 #3
0
 public void OnBodyEntered(Node body)
 {
     TargetHit?.Invoke(new BulletHitInfo
     {
         WorldCoords = _worldCoords,
         Building    = body as IBuilding
     });
     _worldCoords = Vector3.Zero;
     QueueFree();
 }
예제 #4
0
        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;
        }
예제 #5
0
파일: Sickle.cs 프로젝트: Arkhane/Scripts
    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);
            }
        }
    }
예제 #6
0
 public void Visit(TargetHit hit, Vector3 pos, GameObject inst)
 {
     SpawnObject(pos, inst);
 }