Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by BritishGuy · Oct 30, 2014 at 11:02 AM · objectspawncreateplace

Place object in place of ghost.

Hello i am having a little trouble getting my crafting system working correctly, At the moment i can place an object but im having 2 problems,

1) The Ghost object is locked to camera view, it should be on terrain and level "upright" 2) Once i press B the object spawns in a fixed direction from the player, It should place object in place of where ghost was.

Sorry if i did not explain very well, Any suggestions would be great. Thanks.

 using UnityEngine;
 using System.Collections;
 
 public class CampfireBuild : MonoBehaviour {
 
 
 public Transform campfirePrefab;
 public GameObject player;
 
 private bool  canBuild = true;
 
 void  Start (){
         renderer.material.color = Color.green;
     //renderer.material.color.a = 0.5f;
         Color color = renderer.material.color;
         color.a = 0.5f;
         renderer.material.color = color;
 }
 
 void  OnTriggerEnter ( Collider col  ){
     if(col.gameObject.tag == "Terrain" || col.gameObject.tag == "Tree")
     {
         renderer.material.color = Color.red;
         //renderer.material.color.a = 0.5f;
         Color color = renderer.material.color;
         color.a = 0.5f;
         renderer.material.color = color;
         canBuild = false;
     }
 }
 
 void  OnTriggerExit ( Collider col  ){
     if(col.gameObject.tag == "Terrain" || col.gameObject.tag == "Tree")
     {
         renderer.material.color = Color.green;
         //renderer.material.color.a = 0.5f;
         Color color = renderer.material.color;
         color.a = 0.5f;
         renderer.material.color = color;
         canBuild = true;
     }
 }
 
 void  Update (){
     if(Input.GetKeyDown("b") && canBuild == true)
     {
         Instantiate(campfirePrefab, player.transform.position + new Vector3(0, 0, 5), Quaternion.identity);
         player.GetComponent<Crafting>().campFire.SetActive(false);
     }
 }
 }
Comment
Add comment · Show 6
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image yashpal · Oct 30, 2014 at 12:00 PM 0
Share

@BritishGuy, I don't understand what is ghost object. and where you attached this script as component?

avatar image BritishGuy · Oct 30, 2014 at 12:10 PM 0
Share

@yashpal The object i want to build is a floating green box for now that turns red if it hits a collider "Ghosted" until i press B to build it then it will spawn the actual object, The script is attached to the camp fire object

avatar image yashpal · Oct 30, 2014 at 12:47 PM 0
Share

@BritishGuy Instantiate(campfirePrefab, GhostPosition.transform.position, Quaternion.identity); I don't understand your first question you can put your camera as you wanted how it Ghost object block your camera?

avatar image BritishGuy · Oct 30, 2014 at 01:19 PM 0
Share

@yashpal Thanks i used something very similar.

 Instantiate(campfirePrefab, transform.position, transform.rotation);

ok for the Ghost and camera, You know how in RTS games when you want to build a structure a ghost version of the structure will be stuck to the mouse, clicking to place the structure, Isnt there a way to do the same in first person but from a raycast, so where ever i look the ghost object will be where ever i look on the terrain,

Sorry if its sounding complicated, im trying to explain my issue as simple as possible. Thanks.

avatar image BritishGuy · Oct 30, 2014 at 02:20 PM 0
Share

ok i have almost got it, Just cant figure out a way to make the objects always face the camera when i move around.

 void  Update (){
 
         Ray ray = camera.ViewportPointToRay(new Vector3(0.5F, 0.5F, 0));
         RaycastHit hit;
             
             if(Physics.Raycast(ray, out hit, 500))
         {
             //Debug.Log(hit.collider.gameObject.name);
             //Debug.DrawLine (ray.origin, hit.point, Color.green);
             campFire.rigidbody.$$anonymous$$ovePosition(hit.point);
         }
 }
Show more comments

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

27 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

script dosnt creat object where i want it to 1 Answer

Spawn object in cube 2 Answers

'Pre-create object VS Create when needed' Performance difference 1 Answer

Key press hides object and spawns another 2 Answers

Spawn an object? 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges