using System.Collections;
using System.Collections.Generic;
using UnityEngine;
publicclassCardData
{
publicint id;
publicstring name;
publicstring sprite_name;
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
publicclassCardInfo
{
publicint id;
publicCardInfo(int id)
{
this.id = id;
}
}
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
publicclassCard : MonoBehaviour
{
private CardInfo cardInfo;
[SerializeField] private SpriteRenderer spriteRenderer;
publicvoidSetCardInfo(CardInfo cardInfo)
{
this.cardInfo = cardInfo;
}
publicvoidSetSprite(Sprite sp)
{
spriteRenderer.sprite = sp;
}
}
using Newtonsoft.Json;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.U2D;
publicclassMain : MonoBehaviour
{
[SerializeField] private GameObject cardPrefab;
[SerializeField] private SpriteAtlas cardAtlas;
voidStart()
{
TextAsset ts = Resources.Load<TextAsset>("Data/card_data");
string json = ts.text;
Debug.Log(json);
Dictionary<int, CardData> dicCardDatas = JsonConvert.DeserializeObject<List<CardData>>(json).ToDictionary(x => x.id);
GameObject cardGo = Instantiate(cardPrefab);
Card card = cardGo.GetComponent<Card>(); //생성된 프리팹에
CardInfo cardInfo = new CardInfo(100);
card.SetCardInfo(cardInfo);
CardData cardData = dicCardDatas[101];
Sprite sp = cardAtlas.GetSprite(cardData.sprite_name);
card.SetSprite(sp);
}
}
Simple camera shake effect for Unity3d, written in C#. Attach to your camera GameObject. To shake the camera, set shakeDuration to the number of seconds it should shake for. It will start shaking if it is enabled.
카메라의 Transform을 Public으로 설정하여
인스펙터에서 메인카메라를 할당한다면
메인카메라로 보는 오브젝트들의 흔들림을 조정할 수 있습니다.
Shake Duration : 지속 시간
Shake Amount : 흔들림 강도
Decrease Factor : 흘러가는 시간을 조정(Shake Duration 수치 조정)
팀 프로젝트를 하며 적용을 한 장면입니다.
using UnityEngine;
using System.Collections;
publicclassCameraShake : MonoBehaviour
{
// Transform of the camera to shake. Grabs the gameObject's transform// if null.public Transform camTransform;
// How long the object should shake for.publicfloat shakeDuration = 0f;
// Amplitude of the shake. A larger value shakes the camera harder.publicfloat shakeAmount = 0.7f;
publicfloat decreaseFactor = 1.0f;
Vector3 originalPos;
voidAwake()
{
if (camTransform == null)
{
camTransform = GetComponent(typeof(Transform)) as Transform;
}
}
voidOnEnable()
{
originalPos = camTransform.localPosition;
}
voidUpdate()
{
if (shakeDuration > 0)
{
camTransform.localPosition = originalPos + Random.insideUnitSphere * shakeAmount;
shakeDuration -= Time.deltaTime * decreaseFactor;
}
else
{
shakeDuration = 0f;
camTransform.localPosition = originalPos;
}
}
}