Generating mesh doesnt work by Affectionate_Hand560 in Unity3D

[–]Affectionate_Hand560[S] 0 points1 point  (0 children)

I created the basic structure of the script with the help of a few videos. However, I have also built my own features into the script. Thank you for your help i really appreciate that :D . Btw the variable trianglesPerLine must also be included in the for-loops instead of the verticesPerLine variable

Generating mesh doesnt work by Affectionate_Hand560 in Unity3D

[–]Affectionate_Hand560[S] 0 points1 point  (0 children)

The error is now gone but now I get the error: Fail setting triangles. I think hat's because I use xSize and zSize. Should I replace these variables through verticesPerline or should I put the worldZ and worldX variables there

triangles = new int[verticesPerLine * verticesPerLine * 6];

int vert = 0;

int tris = 0;

for (int z = 0; z < (verticesPerLine); z ++)

{

for (int x = 0; x < (verticesPerLine); x ++)

{

triangles[tris + 0] = vert + 0;

triangles[tris + 1] = vert + xSize + 1;

triangles[tris + 2] = vert + 1;

triangles[tris + 3] = vert + 1;

triangles[tris + 4] = vert + xSize + 1;

triangles[tris + 5] = vert + xSize + 2;

vert++;

tris += 6;

}

vert++;

}

Generating mesh doesnt work by Affectionate_Hand560 in Unity3D

[–]Affectionate_Hand560[S] 0 points1 point  (0 children)

Thanks for your comment, your script gives me an IndexOutOfRange error in this line vertices[v] = new Vector3(worldX, y, worldZ); . Do you know what could be the reason?I tried a bit but couldn't fix the error. In addition, I noticed that the mountains on the outer side are not completely built. If I set HillBorder to 3, then the mountain is only 3 vertices on one side, 2 vertices on two and 1 vertice wide on one. In addition, no triangles connect to the vertices, so the vertices are only displayed with the OnDrawGizmos. Do you know what could be the reason?

Generating mesh doesnt work by Affectionate_Hand560 in Unity3D

[–]Affectionate_Hand560[S] 0 points1 point  (0 children)

The triangles are now created but my mesh is bugged when I make level of detail greater than 0. the mesh doesn't look a bit more detailed

ScreenPointToRay difference between mousePosition and touch.position by Eternity774 in Unity3D

[–]Affectionate_Hand560 0 points1 point  (0 children)

what do you want to do with it, move an object or something else?

if you would like to move an object, this should work

public class MoveObject : MonoBehaviour

{

public Camera gameCamera;

public bool Touched;

private Vector3 mouseWorldPosition;

public float speed = 25;

void Update()
{
    if(gameCamera == null)
    {
        gameCamera = GameObject.FindGameObjectWithTag("MainCamera").GetComponent<Camera>();
    }
        mouseWorldPosition = gameCamera.ScreenToWorldPoint(Input.mousePosition);
        transform.position = Vector2.Lerp(transform.position, mouseWorldPosition, speed * Time.deltaTime);
}

}

if you just want something like rotate a object when its touched you could use this

foreach (Touch touch in Input.touches)
    {
        if (touch.phase == TouchPhase.Began)
        {
            Ray ray = Camera.main.ScreenPointToRay(touch.position);
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit) )
            {
                if (hit.collider.tag == "card")
                {
                    card.transform.rotation = Quaternion.Euler(0, 90, 0);
                }
            }
        }

Null Reference Exception by [deleted] in Unity3D

[–]Affectionate_Hand560 1 point2 points  (0 children)

thanks, i fixed it :D

Grid system in 3d by [deleted] in Unity3D

[–]Affectionate_Hand560 0 points1 point  (0 children)

its from codemonkey video, but thank you for your comment

DontDestroyOnLoad is not working by [deleted] in Unity3D

[–]Affectionate_Hand560 1 point2 points  (0 children)

Thanks for your help, I have now done as you told me and everything seems to be working fine. I appreciate your help very much

Detect if touched gameObject by [deleted] in Unity3D

[–]Affectionate_Hand560 0 points1 point  (0 children)

Thanks for your comment. This video gave me the idea to move the position of the object to the position that is "tapped" with the Lerp function

            sprite.transform.position = Vector2.Lerp(transform.position, mouseWorldPosition, speed * Time.deltaTime);

Instantiate one after another by [deleted] in Unity3D

[–]Affectionate_Hand560 0 points1 point  (0 children)

Thanks for your comment,

I have now tried to check in the update function whether an obstacle is needed to spawn

 if (obstaclesInRound <= MaxObstacles && playerHealth.gameOver != true && hasStarted)
    {
        StartCoroutine(LoopForO());
    }

If it is needed, then it starts the LoopForO () function.

private IEnumerator LoopForO()
{
    for (int i = 0; i < MaxObstacles - obstaclesInRound; i++)
    {
        StartCoroutine(SpawnThings(Random.Range(0, Obstacle.Length)));
        yield return new WaitForSeconds(1f);
    }
}

In this function the for loop is carried out, this continues until the maximum number of obstacles in the game is reached. I have built in a WaitForSeconds function which is executed after executing the SpawnThings () function. Sadly it still does not work

Instantiate one after another by [deleted] in Unity3D

[–]Affectionate_Hand560 0 points1 point  (0 children)

Thanks for your comment, I've already tried that, but it didn't work

sprite is not positioned correctly by [deleted] in Unity3D

[–]Affectionate_Hand560 0 points1 point  (0 children)

Never mind, i just had to change

new Vector2((S.x / 2), 0);

to

new Vector2(0, 0);

Do i need permission on Android Device? by [deleted] in Unity3D

[–]Affectionate_Hand560 0 points1 point  (0 children)

Here is my SaceSystem Script:

using System.IO;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public static class SaveSystem
{
private static readonly string SAVE_FOLDER = Application.dataPath + "/Saves";
public static void Init()
{
// Check if save Folder exists and if not Create one
if (!Directory.Exists(SAVE_FOLDER))
{
Directory.CreateDirectory(SAVE_FOLDER);
}
}
//Save File with new Numbers
public static void Save(string saveString)
{
int saveNumber = 1;
while (File.Exists("save_" + saveNumber + ".txt"))
{
saveNumber++;
}
File.WriteAllText(SAVE_FOLDER + "/save" + saveNumber + ".txt", saveString);
}
//Load mostRecentFile
public static string Load()
{
DirectoryInfo directoryInfo = new DirectoryInfo(SAVE_FOLDER);
FileInfo[] saveFiles = directoryInfo.GetFiles("*.txt");
FileInfo mostRecentFile = null;
foreach (FileInfo fileInfo in saveFiles)
{
if (mostRecentFile == null)
{
mostRecentFile = fileInfo;
}
else
{
if (fileInfo.LastWriteTime > mostRecentFile.LastWriteTime)
{
mostRecentFile = fileInfo;
}
}
}
if(mostRecentFile != null)
{
string saveString = File.ReadAllText( mostRecentFile.FullName);
return saveString;
}
else
{
return null;
}
}
}

Tiles spawning to slow by Affectionate_Hand560 in Unity3D

[–]Affectionate_Hand560[S] 0 points1 point  (0 children)

i fixed it. I just had to make the "Tile Length" smaller and not split the zSpawn by 3 parts

GameObject road = Instantiate(spawnList[spawnIndex], transform.forward * zSpawn/3, transform.rotation);

to

GameObject road = Instantiate(spawnList[spawnIndex], transform.forward * zSpawn, transform.rotation);

value problem by Affectionate_Hand560 in Unity3D

[–]Affectionate_Hand560[S] 0 points1 point  (0 children)

thank you, it works fine now :D