I have just started programming and i was learning about arrays. In one of the exercises, when i tried assigning values to the array, it would give me this error:
error CS0029: Cannot implicitly convert type ‘(float, float, float, float, float, float, float, float, float, float, float, float)’ to ‘float[ ]’
This was my script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ejerciciosDeArrays : MonoBehaviour
{
public float[ ] puntuacionesMaximas2 = new float[12];
// Start is called before the first frame update
void Start()
{
puntuacionesMaximas2 = (1.1f, 3.1f, 1.01f, 4.1f, 5.1f, 6.1f, 7.1f, 8.1f, 9.1f, 10.1f, 11.1f, 12.1f);
}
// Update is called once per frame
void Update()
{
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ejerciciosDeArrays : MonoBehaviour
{
public float[] puntuacionesMaximas2 = new float[12];
// Start is called before the first frame update
void Start()
{
puntuacionesMaximas2 = (1.1f, 3.1f, 1.01f, 4.1f, 5.1f, 6.1f, 7.1f, 8.1f, 9.1f, 10.1f, 11.1f, 12.1f);
}
}
Classes should be capitalised too, not camel cased. objects are camel cased. its more identifyable.
if you read the error its telling you “I can’t convert your parameter FLOAT to type of FLOAT ARRAY”
to access the individual elements you could do a for-loop.