Quantcast
Channel: Latest Questions on Unity Answers
Viewing all articles
Browse latest Browse all 171066

Help C#! Adding speed variable when following target transform.

$
0
0
I'm putting the finishing touches on my Pong clone but I am unable to change the enemy's speed once I set him to follow the ball's position.Y First things first, im trying to get it to listen to the speed variable change Second I'm looking for a point in the right direction as far as getting the enemy to change his speed depending on the speed of the ball. Here's my code: C# using UnityEngine; using System.Collections; public class NewEnemyAI : MonoBehaviour { public float yMin, yMax; public Transform target; public float speed; void Update () { float inputSpeed = Input.GetAxisRaw ("Vertical"); transform.position += new Vector3 (0, inputSpeed * speed * Time.deltaTime, 0); } void FixedUpdate () { rigidbody.position = new Vector3 (8.0f, Mathf.Clamp (target.position.y, yMin, yMax), 1.0f); } }

Viewing all articles
Browse latest Browse all 171066

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>