Quantcast
Viewing all articles
Browse latest Browse all 141

Is there a reason this script should lower fps by 10-15 frames?

This script when enabled on my object lowers fps by 10-15 frames, any reason why? I'm pretty sure its the vector3.movetowards but I really badly need it, are there any alternatives that are more performance friendly? using UnityEngine; using System.Collections; public class EnemyMovement : MonoBehaviour { public float movementSpeed; public float animMovementSpeed; Animator animator; public GameObject player; public float distance; public float minDistance; // Use this for initialization void Awake () { animator = GetComponent(); player = GameObject.Find("Player"); } // Update is called once per frame void Update () { if (distance > minDistance) { transform.position = Vector3.MoveTowards(transform.position, player.transform.position, movementSpeed * Time.deltaTime); animator.SetFloat("MovementSpeed", 1.0f); } if(distance <= minDistance) { animator.SetFloat("MovementSpeed", 0.0f); } distance = Vector3.Distance(transform.position, player.transform.position); if (player.transform.position.x > transform.position.x) { transform.eulerAngles = new Vector2(0, 180); } else { transform.eulerAngles = new Vector2(0, 0); } } }

Viewing all articles
Browse latest Browse all 141

Trending Articles