Hi
I’m trying to use Parallel.For in a script file, but I get the following error:
error CS0234: The type or namespace name
Tasks' does not exist in the namespace
System.Threading’. Are you missing an assembly reference?
Here is my code for that section (see the commented out for loop I’m trying to replace just below it):
private void DisplaceHexagon(GameObject hexagon, Texture2D heightmap, float displacementStrength)
{
Mesh mesh = ((MeshFilter)hexagon.GetComponent("MeshFilter")).mesh;
Vector3[] vertices = new Vector3[mesh.vertices.Length];
mesh.vertices.CopyTo(vertices, 0);
int[] textureCoordX = mesh.uv.Select(item => (int)(item.x * heightmap.width)).ToArray();
int[] textureCoordY = mesh.uv.Select(item => (int)(item.y * heightmap.width)).ToArray();
Parallel.For(0, vertices.Length, i =>
{
vertices<em>.z = -heightmap.GetPixel(textureCoordX<em>, textureCoordY_).grayscale * displacementStrength;_</em></em>
* });*
_ /for (int i = 0; i < vertices.Length; i++)
{
vertices.z = -heightmap.GetPixel(textureCoordX, textureCoordY).grayscale * displacementAmount;
}/_
* mesh.vertices = vertices;*
* }*
I’ve set my mono project target framework to Mono / .Net 4 in the general build options. The project builds fine in Mono Develop from the Build menu and I’ve also cleaned the solution and re-built. Also, the Unity game runs fine when targeting Mono / .Net 4 if I’m not using Parallel.For and use the normal for loop instead.
I have the following using directives at the top of my file:
using UnityEngine;
using System.Collections;
using UnityEditor;
using System.Collections.Generic;
using System.Linq;
using System;
using System.Threading;
using System.Threading.Tasks;
and I have the following references in my project:
UnityEditor.dll
UnityEngine.dll
System
System.Core
System.Xml
If I type it out in the code intellisense even picks up the path to Parallel.For correctly and I can right-click on Parallel and “resolve” which adds the correct “using” line at the top of my file. Yet Unity gives me the above error.
Does anyone know what I’m doing wrong here? Thank you in advance for any assistance.