- Home /
Question by
pbahli1 · Jul 20, 2021 at 11:39 AM ·
unity 2dwebglmovetowards
prefab movetowards correctly in editor and windows build but not webgl build
my game instantiates a prefab via button and it works fine in the editor and windows build but not the webgl build.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FrogAI : MonoBehaviour
{
public Player player;
private Vector2 position;
private Vector2 target;
private Vector2 target2 ;
private Vector2 target3 ;
public float speed;
bool isRunning;
bool counted;
void Start()
{
isRunning=true;
player = GameObject.FindGameObjectWithTag("player").GetComponent<Player>();
target = new Vector2(Random.Range(-3.5f,-2.5f),Random.Range(0f,-1.5f));
target2 = new Vector2(Random.Range(.5f,1f),Random.Range(-2.25f,-3f));
target3 = new Vector2(6f,Random.Range(-2f,-3f));
position = gameObject.transform.position;
}
// Update is called once per frame
void Update()
{
Debug.Log(this.transform.position.x +" "+ this.transform.position.y);
if(isRunning&&player.currentMultiplyer<player.maxMultiplyer){
counted = true;
player.currentMultiplyer+=player.bonusPerFrog;
isRunning=false;
}
speed = player.speedInc;
float step = speed*Time.deltaTime;
transform.position = Vector2.MoveTowards(this.transform.position,target,step);
if(Vector2.Distance(this.transform.position,target)<.01){
target = target2;
}
if(Vector2.Distance(this.transform.position,target)<.001){
target = target3;
}
if(Vector2.Distance(transform.position,target3)<0.1f){
if(counted){
player.currentMultiplyer-=player.bonusPerFrog;
}
Destroy(transform.root.gameObject);
if(this.gameObject.name=="queenFrog(Clone)"){
player.frogs+=player.queenFrogValue;
}else{
player.frogs++;
}
}
}
public void spawnFrog(){
}
}
Comment
Your answer
Follow this Question
Related Questions
hi webgL error and camira 0 Answers
How do I setup a popup canvas ? 0 Answers
How do I moveTowards all the items in a list one at a time? 1 Answer
Error when loading Unity WebGL 1 Answer
Unity WebGL video black screen appears in Safari 13 0 Answers