- Home /
Snapping Objects At Runtime
Hi people, I am creating a game where I need an object to snap into position when I enter a trigger. I know the trigger works because I used the destroy command on it, and that worked fine.
When I drag my item in to the trigger and take my finger off the mouse button I would like it to snap to that pos/gameobject, If it is not in a trigger then I would like it to return to another point in the game world (a kind of item bar).
Anyway, here is the code I have tried and I know it will probably seem really obvious and silly of me to ask this...
using UnityEngine;
using System.Collections;
public class SnapPeg : MonoBehaviour {
public Transform holeTransform;
public Transform pegTransform;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnTriggerEnter(Collider other)
{
pegTransform.transform.position = holeTransform.transform.position;
//Destroy(peg);
}
}
I hope someone can help and I would like to say a pre-thanks =]
Cas.
Answer by jasonbelmonti · Aug 29, 2011 at 06:23 PM
Huh. I would benefit from an answer to this question as well
Your answer
Follow this Question
Related Questions
Vertex snapping of any mesh at runtime 2 Answers
AR Object stuck in front of camera 0 Answers
Placing an object 1 Answer