Instantiate a an object using c# (noob)?

Hi!

I’ve been using XNA for so long that I don’t really get how to do simple stuff on unity,
what I’m trying to do is create a class “Card” and that card a Sprite property,
then be able to create a new Card and instantiate it on the scene.

So I tried something like this:

using UnityEngine;
using System.Collections;

public class Main : MonoBehaviour {

    // Use this for initialization
    void Start () {
        Carta back = new Carta();
        back.imagen = Resources.Load ("backcard", Sprite);
        Instantiate(back, new Vector3(0, 0, 0), new Quaternion());
    }
   
    // Update is called once per frame
    void Update () {

    }
}

public class Carta{
    public Sprite imagen;
    public string nombre;
}

But it does nothing (the main.cs script is attached to the main camera).
Obviously I don’t know what I’m doing… I tried with public class Carta : Object and it’s the same.

Could someone tell me how to do something like this?
The idea is to be able to create a lot of different Cards (class Carta) programmatically and instantiate them when needed.

(Game is 2D).
Hope someone can help me, thanks :slight_smile:

It works now,
I did it like this:

using UnityEngine;
using System.Collections;

public class Main : MonoBehaviour {

    // Use this for initialization
    void Start () {
        for(int i = 1; i < 5; i++){
            GameObject c = new GameObject("Carta" + i);
            c.AddComponent("SpriteRenderer");
            c.transform.position = new Vector3(-3 + i, 0, 0);
            SpriteRenderer render = c.GetComponent<SpriteRenderer>();
            Sprite sprite = new Sprite();
            Texture2D textura = (Texture2D) Resources.Load ("backcard", typeof(Texture2D));
            sprite = Sprite.Create(textura, new Rect(0, 0, 320, 448), new Vector2(0, 0), 100.0f);
            render.sprite = sprite;
        }
    }
   
    // Update is called once per frame
    void Update () {

    }
}

No need to create any classes,
just create the gameobjects, pass them a spriterenderer, and get the texture from the resources folder.
Attached the script to the main camera, on play 4 cards are displayed on the scene.