Quantcast
Channel: Questions in topic: "clone"
Viewing all articles
Browse latest Browse all 508

Updating animator for instantiated/cloned object

$
0
0
Hi guys, the cloned object is not playing the "highlighted" animation. The initial object does play the animation, but once it cloned on the scene, the animation is not playing. I try attaching the duplicate code to an empty and parenting this one to it. I also try making the object a child to the empty, It does not work. I have two codes, one attached to the object that will collide with the main OBJECT and will change the animation. Another is a duplicate/clone script attached to the camera. The animation does work on the original object but not on the instantiated/cloned object. Would really appreciate your assistance on this one. using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class DetectObjectonCollision : MonoBehaviour { public Animator objectAnimator; public GameObject Object; void Start() { Object = GameObject.FindWithTag("object"); objectAnimator = object.GetComponent(); } // Use this for initialization void OnCollisionEnter2D() { Debug.Log("hit"); ScoreScript.scoreValue += 1; objectAnimator.SetFloat("Collide", 1); Debug.Log(ScoreScript.scoreValue); } void OnCollisionExit2D() { objectAnimator.SetFloat("Collide", 0); } } Duplicate script using UnityEngine; using System.Collections; public class DuplicateObject : MonoBehaviour { public GameObject prefab; public float minSpawnTime = 1.0f; public float maxSpawnTime = 3.0f; public float distFromCamera = 10.0f; private float timer = 0.0f; private float nextTime; void Start () { nextTime = Random.Range(minSpawnTime, maxSpawnTime); } void Update () { timer += Time.deltaTime; prefab = GameObject.FindWithTag("Object"); if (timer > nextTime) { Vector3 pos = new Vector3(Random.value, Random.value, distFromCamera); pos = Camera.main.ViewportToWorldPoint(pos); Instantiate(prefab, pos, Quaternion.identity); Debug.Log("Object created"); timer = 0.0f; nextTime = Random.Range(minSpawnTime, maxSpawnTime); } } }

Viewing all articles
Browse latest Browse all 508

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>