コード例 #1
0
ファイル: Movement.cs プロジェクト: Elam92/CannonGame
        // Moves the object on the X and Z axis.
        public void Move(float horizontal, float vertical)
        {
            float x = horizontal * speed * time.GetTime();
            float z = vertical * speed * time.GetTime();

            Vector3 newPosition = new Vector3(x, 0, z);

            self.position += newPosition;
        }
コード例 #2
0
        // Deactivate the explosion when its reached its lifetime.
        void Update()
        {
            lifeTime -= unityTime.GetTime();

            if (lifeTime < 0)
            {
                Deactivate();
            }
        }
コード例 #3
0
        // Moves the target marker around the Player, restricted by a maximum range.
        public void Move(float horizontal, float vertical)
        {
            float x = horizontal * speed * time.GetTime();
            float z = vertical * speed * time.GetTime();

            Vector3 newTargetLocation = self.position + new Vector3(x, 0, z);

            // Get distance from center to target.
            Vector3 toTarget = newTargetLocation - origin;

            float distance = toTarget.sqrMagnitude;

            // If distance is greater than the range limit, then keep it within bounds.
            if (distance > rangeCheck)
            {
                newTargetLocation = origin + (toTarget.normalized * rangeLimit);
            }

            self.position = newTargetLocation;
        }
コード例 #4
0
        // Update is called once per frame
        void Update()
        {
            timeElapsed += unityTime.GetTime();

            if (timeElapsed > timeToSpawn)
            {
                enemySpawner.Spawn();

                // Get ready for the next spawn.
                timeElapsed = 0;
                timeToSpawn = Random.Range(0, maxSpawnTime);
            }
        }
コード例 #5
0
ファイル: MovementTests.cs プロジェクト: Elam92/CannonGame
        public void Initialize_Movement()
        {
            var go = new GameObject();

            objectTransform          = go.transform;
            objectTransform.position = Vector3.zero;

            var speed = 1f;

            IUnityTime timeInformation = Substitute.For <IUnityTime>();

            timeInformation.GetTime().Returns(1f);

            basicMovement = new Movement(objectTransform, speed, timeInformation);
        }
コード例 #6
0
        public void InitializeTargetMovement()
        {
            var go = new GameObject();

            mover          = go.transform;
            mover.position = Vector3.zero;

            origin     = Vector3.zero;
            rangeLimit = 2f;

            var speed = 1f;

            IUnityTime timeInformation = Substitute.For <IUnityTime>();

            timeInformation.GetTime().Returns(1f);

            targetMovement = new TargetMovement(mover, origin, speed, rangeLimit, timeInformation);
        }