S
S
Savab2020-11-20 15:14:11
Unity
Savab, 2020-11-20 15:14:11

Why is the player not moving towards another object?

The object does not move to another, but the code is correct in my opinion;

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

public class PLAYER1 : MonoBehavior
{
public GameObject goal1;
public GameObject goal2;

bool check = false;

void Update()
{
if(check) transform.position = Vector3.MoveTowards(transform.position, goal1.transform.position, 2f * Time.deltaTime);
if(!check) transform.position = Vector3.MoveTowards(transform.position, goal2.transform.position, 2f * Time.deltaTime);
transform.rotation *= Quaternion.Euler(0f,0f,1f);
}
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question