Solution given by unity development team.
Fruit ninja : Bomb works well but stroke still works only 50% on devices
Update: I found the fault of the bomb and fixed it. However, it appears that the stroke remains unsolved.
The script affecting this is the line script. Does anyone have any ideas how to fix this?
using System.Collections;
using UnityEngine;
public class LineCreator : MonoBehaviour
{
int vertexCount = 0;
bool mouseDown = false;
LineRenderer line;
public GameObject blast;
void Awake()
{
line = GetComponent<LineRenderer>();
}
void Start()
{
}
void Update()
{
if (Application.platform == RuntimePlatform.Android)
{
if (Input.touchCount > 0)
{
if (Input.GetTouch(0).phase == TouchPhase.Moved)
{
line.SetVertexCount(vertexCount + 1);
Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
line.SetPosition(vertexCount, mousePos);
vertexCount++;
//BoxCollider2D box = gameObject.AddComponent<BoxCollider2D>();
//box.transform.position = line.transform.position;
//box.size = new Vector2(0.1f, 0.1f);
EdgeCollider2D eCol = gameObject.AddComponent<EdgeCollider2D>();
Vector3[] pos = new Vector3[line.positionCount];
line.GetPositions(pos);
Vector2[] pos2 = new Vector2[line.positionCount];
for (int i = 0; i < line.positionCount; i++)
{
pos2[i] = new Vector2(pos[i].x, pos[i].y);
}
eCol.points = pos2;
}
if (Input.GetTouch(0).phase == TouchPhase.Ended)
{
vertexCount = 0;
line.SetVertexCount(0);
BoxCollider2D[] collidors = GetComponents<BoxCollider2D>();
foreach (BoxCollider2D box in collidors)
{
Destroy(box);
}
}
}
if (Input.GetMouseButtonDown(0))
{
mouseDown = true;
vertexCount = 0;
line.SetVertexCount(0);
}
EdgeCollider2D[] colliders = GetComponents<EdgeCollider2D>();
//edge changed to box
foreach (EdgeCollider2D box in colliders)
{
Destroy(box);
}
if (mouseDown)
{
line.SetVertexCount(vertexCount + 1);
Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
line.SetPosition(vertexCount, mousePos);
vertexCount++;
BoxCollider2D box = gameObject.AddComponent<BoxCollider2D>();
box.transform.position = line.transform.position;
box.size = new Vector2(0.1f, 0.1f);
}
if (Input.GetMouseButtonUp(0))
{
mouseDown = false;
vertexCount = 0;
line.SetVertexCount(0);
//edge changed to box
BoxCollider2D[] collidors = GetComponents<BoxCollider2D>();
foreach (BoxCollider2D box in collidors)
{
Destroy(box);
}
}
}
// else if (Application.platform == RuntimePlatform.WindowsPlayer)
else
{
if (Input.GetMouseButtonDown(0))
{
mouseDown = true;
}
if (mouseDown)
{
line.positionCount = vertexCount + 1;
Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
line.SetPosition(vertexCount, mousePos);
vertexCount++;
//BoxCollider2D box = gameObject.AddComponent<BoxCollider2D>();
//box.transform.position = line.transform.position;
//box.size = new Vector2(0.5f, 0.5f);
EdgeCollider2D edge = gameObject.AddComponent<EdgeCollider2D>();
Vector3[] pos = new Vector3[line.positionCount];
line.GetPositions(pos);
Vector2[] pos2 = new Vector2[line.positionCount];
for (int i = 0; i < line.positionCount; i++)
{
pos2[i] = new Vector2(pos[i].x, pos[i].y);
}
edge.points = pos2;
}
if (Input.GetMouseButtonUp(0))
{
mouseDown = false;
vertexCount = 0;
line.positionCount = 0;
//BoxCollider2D[] colliders = GetComponents<BoxCollider2D>();
//foreach (BoxCollider2D box in colliders)
//{
// Destroy(box);
//}
//edge changed to box
EdgeCollider2D[] colliders = GetComponents<EdgeCollider2D>();
foreach (EdgeCollider2D box in colliders)
{
Destroy(box);
}
}
}
}
void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.tag == "bomb")
{
GameObject b = Instantiate(blast, collision.transform.position, Quaternion.identity) as GameObject;
Destroy(collision.gameObject);
blast.SetActive(true);
}
}
}
Hello @JulianHSC ! Could you attach the project for the further investigation?
Best regards, Vita
Hello Vita, Thank you for co$$anonymous$$g to the rescue again. No password required : https://drive.google.com/file/d/1akE$$anonymous$$R8eqHrJA0_0$$anonymous$$e_B1xwXfvJ$$anonymous$$kuup-/view?usp=sharing.
As far as I know it works on the smartphone, right (recently tested on Huawei Honor 10 it works fine)? Unfortunately, I doesn't have the opportunity to test on the tablet. Could you attach a video of the issue I will check the code if everything works as it supposes to.
Vita
Hello,
Accept my apologies for the delay in response and thanks for detailed information! Had a look at your code it seems correct. The issue is also reproducible on my device. Could you fill a bug report for that?
Best regards, Vita
@vitaskruibyte , It's been some time now. Has the bug been found? Which unity version is suitable to fix the error? I would appreciate a reply so I can close this case. $$anonymous$$y bomb also doesn't work properly.
Answer by Beginner_at_Unity · Aug 20, 2019 at 07:27 AM
@vitaskruibyte. OK thank you. I will do that soon. I got another case to post here.
Follow this Question
Related Questions
Longest distance between straight line and a curve. 1 Answer
How to get a drawn line to snap into a shape? 0 Answers
Textures not showing properly? 0 Answers
Function Update not working 1 Answer
[C#] Enum not working properly 2 Answers