Why doesn't my object move when I use transform.position?
At the moment, I'm just trying to choose a random card from a deck and place it in a designated "slot". When I review the console, I receive the following:
new card position = (-6.5, -1.9, 0.0) UnityEngine.Debug:Log (object) TestingScript:DrawCard () (at Assets/TestingScript.cs:18) UnityEngine.EventSystems.EventSystem:Update () (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/EventSystem/EventSystem.cs:385)
current card position = (8.3, 3.1, 0.0) UnityEngine.Debug:Log (object) TestingScript:DrawCard () (at Assets/TestingScript.cs:16) UnityEngine.EventSystems.EventSystem:Update () (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/EventSystem/EventSystem.cs:385)
I can also confirm that the object is not set to static and that Timescale = 1. I also attempted using transform.localPosition but ended up with the same results. My card won't move from it's original position.
Additional Information:
I'm not sure if it's relevant, but the script that I'm calling is on my GameManager, my cards are parented to an empty labeled "Cards". Each card within the empty consists of two sprites (a card back & a card front). The card front is parented to the card back, my plan was to use the renderer to enable the front sprite when I wanted to reveal what the card was.
using UnityEngine;
using System.Collections.Generic;
public class TestingScript : MonoBehaviour
{
public List<Card> deck = new List<Card>();
public Transform[] cardSlots;
public bool[] availableCardSlots;//will be used eventually to check if the card slot is available.
public void DrawCard()
{
if (deck.Count >= 1)
{
Card randCard = deck[Random.Range(0, deck.Count)];
randCard.gameObject.SetActive(true);
Debug.Log("current card position = " + randCard.transform.position);
randCard.transform.position = cardSlots[0].position;
Debug.Log("new card position = " + randCard.transform.position);
deck.Remove(randCard);
return;
}
}
}
Your answer
Follow this Question
Related Questions
Getting player last seen position? 2 Answers
Do you need to have specific script types for different mobile platforms? 1 Answer
how do I rezolve "look rotation viewing vector is zero"? 1 Answer
[SOLVED] get object which is nearby to mouse 1 Answer
Unity Rigidbody fps controller jumps higher each time. 0 Answers