TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Ömer Faruk Çalışkan
NA
45
1.7k
I want an array of double numbers (1.64, etc.). I want to take them..
Feb 15 2021 10:53 PM
I have an array of double numbers (1.64, etc.). I want to take them randomly and use it to instantiate in that position(number). I looked up but what I have found :
var element = myArray[Random.Range(0, myArray.Length)];
// this sort of thing. As it seems that it doesn't get the double .
so look (List<> ) but it also problematic whenever I try adding a double value it gives an absurd error so I decided to use :
double
[] barrierleftList = {1.23, 4.56, 7.89};
//14th line
but I have some problem with that too
randomZ = barrierleftList[Random.Range(0, barrierleftList.Length)];
//46th line
// when I run this it gives:
Assets\instantiate.cs(46,19): error CS0266: Cannot implicitly convert type 'double' to 'int'. An explicit conversion exists (are you missing a cast?)
This is my problem.
btw Thanks even for reading :)
HERE IS MY FULL CODE! ( why here you might ask because it is easier to follow)
using
System.Collections;
using
System.Collections.Generic;
using
UnityEngine;
public
class
instantiate : MonoBehaviour
{
public
Transform bars;
private
Vector3 nextBarsSpawn;
public
Transform barrierleft;
public
Transform barrierright;
private
Vector3 nextbarrierleftSpawn;
private
Vector3 nextbarrierrightSpawn;
private
int
randomZ;
double
[] barrierleftList = {1.23, 4.56, 7.89};
double
[] barrierrightList = {1.23, 4.56, 7.89};
/* List<double> nextbarrierleftList = new List<double>();
items.Add(1.23);
items.Add(4.56);
items.Add(7.89);
// This will give you a double[3] array with the items of the list.
double[] barrierleftList = barrierleftList.ToArray();
*/
void
Start()
{
nextBarsSpawn.x=24;
nextBarsSpawn.y=4;
nextbarrierleftSpawn.x=18;
nextbarrierleftSpawn.y=4;
nextbarrierrightSpawn.x=18;
nextbarrierrightSpawn.y=4;
StartCoroutine(spawnBars());
StartCoroutine(spawnbarrierleft());
//StartCoroutine(spawnbarrier());
}
// Update is called once per frame
void
Update()
{
}
IEnumerator spawnbarrierleft()
{
// left barrier
yield
return
new
WaitForSeconds(1);
//randomZ=Random.Range(-1,2);
randomZ = barrierleftList[Random.Range(0, barrierleftList.Length)];
nextbarrierleftSpawn.z=randomZ;
Instantiate(barrierleft, nextbarrierleftSpawn, barrierleft.rotation);
nextbarrierleftSpawn.x += 8;
StartCoroutine(spawnbarrierleft());
}
IEnumerator spawnBars()
{
yield
return
new
WaitForSeconds(1);
Instantiate(bars, nextBarsSpawn, bars.rotation);
nextBarsSpawn.x += 8;
StartCoroutine(spawnBars());
}
}
Reply
Answers (
1
)
can we learn datascience with.net?
I have data frame, in first column there are id's which are randomly.