- Home /
This post has been wikified, any user with enough reputation can edit it.
Question by
MrP · Nov 12, 2012 at 12:26 PM ·
c#drag and drop
How to make my cards dragable in my solitaire game?
Hi im making a solitaire game but i dont know how to make my cards dragable
using UnityEngine;
using System.Collections;
public class SetupCards : MonoBehaviour
{
int numberOfCards = 52;
int numberOfCardSorts = 4;
public float verticalSize = 1.4f;
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
}
void OnGUI()
{
int currentSort = 0;
int cardNumber = 0;
for (int i = 0; i < numberOfCards; ++i)
{
int numberOfCardsPerSort = numberOfCards / numberOfCardSorts;
float cardSizeX = Screen.width / numberOfCardsPerSort;
if (cardNumber == numberOfCardsPerSort)
{
++currentSort;
cardNumber = 0;
}
Vector2 cardSize = new Vector2(cardSizeX, cardSizeX * verticalSize);
Rect rect = new Rect(
cardSize.x * cardNumber,
cardSize.y * currentSort,
cardSize.x,
cardSize.y);
string texturePath = "Textures/cards/";
switch (currentSort)
{
case 0:
texturePath += "diamond/diamond_";
break;
case 1:
texturePath += "clover/clover_";
break;
case 2:
texturePath += "heart/heart_";
break;
case 3:
texturePath += "spade/spade_";
break;
}
texturePath += cardNumber.ToString();
//Debug.Log(texturePath);
Texture texture = Resources.Load(texturePath) as Texture;
GUI.Label(rect, texture);
++cardNumber;
}
}
}
Comment
you might wanna have a look at this: http://docs.unity3d.com/Documentation/ScriptReference/$$anonymous$$onoBehaviour.On$$anonymous$$ouseDrag.html
Answer by salad__fingers · Nov 12, 2012 at 03:20 PM
You can also make them rigidbodies with a colliders and on the camera add the Drag Rigidbody script, it's a default Unity script, so no writing needed.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
A node in a childnode? 1 Answer
Distribute terrain in zones 3 Answers
Scrolling typewriter effect 5 Answers
Why does the C# scripting libraries not conform to .NET naming convensions? 2 Answers